JDBC设计理念浅析 JDBC简介(一)
概念


JDBC功能核心
数据库查询
- 连接数据库
- 执行SQL
- cmd打印结果
- 连接数据库
- 执行SQL
- 处理返回结果
JDBC架构设计
- 提供了一套纯粹的JAVA API给应用程序开发者
- 提供了一套低级别的JDBC driver API给数据库驱动开发者
JDBC API
官方相关介绍
What the
java.sql Package Contains
The
java.sql package contains API for the following:
- Making a connection with a database via the
facility 通过驱动管理器工具与数据库建立连接DriverManager
class 类 -- makes a connection with a driver 与驱动程序建立连接
DriverManagerclass 类-- provides permission when code running within a Security Manager, such as an applet, attempts to set up a logging stream through the
SQLPermission
在安全管理器(如applet)中运行的代码试图通过驱动程序管理器设置日志流时,提供权限DriverManager
interface 接口 -- provides the API for registering and connecting drivers based on JDBC technology ("JDBC drivers"); generally used only by the
Driver
class提供基于JDBC技术的驱动程序注册和连接API(“JDBC驱动程序”);通常只被DriverManager类使用DriverManager
class 类 -- provides properties for a JDBC driver; not used by the general user 为JDBC驱动程序提供属性;一般用户不使用
DriverPropertyInfo
- Sending SQL statements to a database 向数据库发送SQL语句
-- used to send basic SQL statements 执行对象,用于发送基本的SQL语句
Statement-- used to send prepared statements or basic SQL statements (derived from
PreparedStatement
) 用于发送准备好的语句或基本SQL语句(从Statement派生)Statement
-- used to call database stored procedures (derived from
CallableStatement
) 用于调用数据库存储过程(从PreparedStatement 派生)PreparedStatement
interface 接口 -- provides methods for creating statements and managing connections and their properties 提供用于创建语句和管理连接及其属性的方法
Connection-- provides savepoints in a transaction 在事务中提供Savepoint保存点
Savepoint
- Retrieving and updating the results of a query 检索和更新查询的结果
interface 接口
ResultSet
- Standard mappings for SQL types to classes and interfaces in the Java programming language SQL类型到Java编程语言中的类和接口的标准映射
interface 接口-- mapping for SQLArray
ARRAY SQL ARRAY映射
interface 接口-- mapping for SQLBlob
BLOB SQL BLOB映射
interface接口 -- mapping for SQLClob
CLOB SQL CLOB 映射
class 类-- mapping for SQLDate
DATE
interface 接口 -- mapping for SQLNClob
NCLOB
interface 接口-- mapping for SQLRef
REF
interface 接口-- mapping for SQLRowId
ROWID
interface 接口-- mapping for SQLStruct
STRUCT
interface 接口-- mapping for SQLSQLXML
XML
class 类-- mapping for SQLTime
TIME
class 类-- mapping for SQLTimestamp
TIMESTAMP
class 类-- provides constants for SQL types 为SQL类型提供常量Types
- Custom mapping an SQL user-defined type (UDT) to a class in the Java programming language 自定义将SQL用户定义类型(UDT)映射到Java编程语言中的类
interface -- specifies the mapping of a UDT to an instance of this class 指定UDT到该类实例的映射SQLData
interface -- provides methods for reading UDT attributes from a stream 提供从流中读取UDT属性的方法SQLInput
interface -- provides methods for writing UDT attributes back to a stream 提供将UDT属性写回流的方法SQLOutput
- Metadata 元数据
interface -- provides information about the database 提供有关数据库的信息DatabaseMetaData
interface -- provides information about the columns of aResultSetMetaData
object 提供有关ResultSet对象的列的信息ResultSet
interface -- provides information about the parameters toParameterMetaData
commands 为PreparedStatement命令提供有关参数的信息PreparedStatement
- Exceptions 异常
-- thrown by most methods when there is a problem accessing data and by some methods for other reasons 当访问数据存在问题时大多数方法都会抛出这个异常,还有一些方法是其他原因抛出这个异常。
SQLException-- thrown to indicate a warning 抛出以表示警告
SQLWarning-- thrown to indicate that data may have been truncated 抛出以指示数据可能已被截断
DataTruncation-- thrown to indicate that not all commands in a batch update executed successfully 抛出以指示批处理更新中并非所有命令都已成功执行
BatchUpdateException
核心
一般流程
第一个JDBC示例
准备
导包
示例代码
package jdbc.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
/**
* 第一个JDBC
* @author noteless
*/
public class FirstJDBC {
public static void main(String[] args) throws Exception {
//1、注册驱动
Class.forName("com.mysql.jdbc.Driver");
//数据库连接所需参数
String user = "root";
String password = "123456";
String url = "jdbc:mysql://localhost:3306/sampledb?useUnicode=true&characterEncoding=utf-8";
//2、获取连接对象
Connection conn = DriverManager.getConnection(url, user, password);
//设置sql语句
String sql = "select * from student";
//3、获得sql语句执行对象
Statement stmt = conn.createStatement();
//4、执行sql并保存结果集
ResultSet rs = stmt.executeQuery(sql);
//5、处理结果集
while (rs.next()) {
System.out.print("id:" + rs.getInt(1));
System.out.print(",姓名:" + rs.getString(2));
System.out.print(",年龄:" + rs.getInt(3));
System.out.println(",性别:" + rs.getString(4));
}
//6、资源关闭
rs.close();
stmt.close();
conn.close();
}
}
结果

总结
JDBC设计理念浅析 JDBC简介(一)的更多相关文章
- JDBC驱动程序注册 JDBC简介(二)
使用JDBC进行数据库操作的第一步就是驱动注册(当然你得先导入JAR). 驱动注册有多种方式,第一步必然是获得正确的驱动名称与URL格式 驱动名称与URL格式 RDBMS 驱动程序名称 ...
- Mybatis配置信息浅析 MyBatis简介(二)
官方文档入门篇中有明确说明 每个基于 MyBatis 的应用都是以一个 SqlSessionFactory 的实例为中心的. SqlSessionFactory 的实例可以通过 SqlSessionF ...
- Mybatis sql映射文件浅析 Mybatis简介(三)
简介 除了配置相关之外,另一个核心就是SQL映射,MyBatis 的真正强大也在于它的映射语句. Mybatis创建了一套规则以XML为载体映射SQL 之前提到过,各项配置信息将Mybatis应用的整 ...
- Mybatis sql映射文件浅析 Mybatis简介(三) 简介
Mybatis sql映射文件浅析 Mybatis简介(三) 简介 除了配置相关之外,另一个核心就是SQL映射,MyBatis 的真正强大也在于它的映射语句. Mybatis创建了一套规则以XML ...
- 理解JNDI中 java:comp/env/jdbc/datasource 与 jdbc/datasource 的不同之处(转)
在描述JNDI,例如获得数据源时,JNDI地址有两种写法,例如同是 jdbc/testDS 数据源: A:java:comp/env/jdbc/testDS B:jdbc/testDS 这两种写 ...
- 【JDBC&Dbutils】JDBC&JDBC连接池&DBUtils使用方法(重要)
-----------------------JDBC---------- 0. db.properties文件 driver=com.mysql.jdbc.Driver url=jdbc: ...
- Unit01: JDBC原理 、 JDBC基础编程
Unit01: JDBC原理 . JDBC基础编程 这个文件里面有两块内容: 1.用比较麻烦的方式连接数据库,test1(),test4() 2.创建DBTool,测试DBTool连接数据库 ,tes ...
- 通明讲JDBC(一)–认识JDBC
本章记录了jdbc的简单使用方式! 0,jdbc的作用 1,jdbc入门准备工作 2,jdbc注册驱动 3,使用jdbc对数据库CRUD 0,jdbc的作用 与数据库建立连接.发送操作数据库的语句并处 ...
- oracle数据库连接问题org.springframework.jdbc.support.MetaDataAccessException: JDBC DatabaseMetaData method not implemented by JDBC driver - upgrade your driver...
org.springframework.jdbc.support.MetaDataAccessException: JDBC DatabaseMetaData method not implement ...
随机推荐
- 近期待学习&目标内容
算法 Splay 树链剖分 AC自动机 问题 bzoj1010[HNOI2008]玩具装箱 bzoj1096[ZJOI2007]仓库建设 bzoj1597[USACP2008 Mar]土地购买 bzo ...
- 【转】Android studio安装与配置
Android studio安装与配置 1.首先下载Android studio安装包,可以从http://www.android-studio.org/下载最新版本,这里采用3.0版本进行演示,对应 ...
- java方法的调用
各种方法的调用实例 package cn.edu.fhj.day004; public class FunctionDemo { // 定义全局的变量 public int a = 3; public ...
- 非vue-cli的花括号闪现问题
<div id="app" v-cloak></div>[v-cloak] { display: none;}这种方式可以解决网速较慢,vue.js文件还没 ...
- 邮件服务器 postfix
背景介绍 邮件服务器普遍需要一个主机名来使得mail from 以"账号@主机名"方式显示.由于外网上垃圾邮件太多,现在已不使用ip发邮件,很多网络供应商都会对来源不明的邮件进行限 ...
- [LeetCode] Shifting Letters 漂移字母
We have a string S of lowercase letters, and an integer array shifts. Call the shift of a letter, th ...
- position 几个属性的作用
//定位一般都会配合left 和 top 一起使用; //静态定位 : 元素默认位置; 不脱标 不常用position:static; //相对定位 : 相对于元素本身之前的位置进行定位;不脱标pos ...
- Python基础之面向对象3(继承)
一.继承相关概念 1.语法: 2.定义: 3.优缺点: 4.相关概念: 5.相关内置函数: 6.继承内存图: 7.多继承: 二.多态相关概念 1.定义及作用: 2.重写概念: 3.运算符重载: 定义: ...
- Json----简单介绍
Json 先分享一个网站http://www.bejson.com/,这个是用来检测Json文件的错误的,Json文件一般不好查找错误. 看懂Json只需要四句话: 对象表示为键值对 数据由逗号分隔 ...
- NumPy库实现矩阵计算
随着机器学习技术越来越向着整个社会进行推广,因此学好线性代数和Python当中的numpy库就相当重要了.我们应该知道numpy库的使用是sklearn库和opencv库的基础.主要用于矩阵的计算.当 ...