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 ...
随机推荐
- BZOJ2649 : riddle
题意同3495,但是内存限制收紧了,不能采用3495的前后缀优化建图的方式. 注意到“每个集合恰好选择一个点”可以放宽成“每个集合最多选择一个点”,对于最后求出的方案里,如果某个集合没选点,任选一个就 ...
- 【类与对象】--------java基础学习第六天
类与对象 1. 对于面向对象的开发来讲也分为三个过程: OOA(面向对象分析) OOD(面向对象设计) OOP(面向对象编程) 2. 面向对象的基本特征 2.1. 封装:保护内部操作(属性,方法)不被 ...
- kettle web化
kettle web化 通过Java API调用kettle核心代码,并基于Spring Boot提供简易的Web管理界面. 背景 在工作中,通过kettle这款ETL产品进行数据处理时,是通过kit ...
- Flutter 编写内联文本
使用Text.rich或者RichText ListView( children: <Widget>[ Text.rich( TextSpan( text: 'Text: ', child ...
- swust oj 1013
哈希表(开放定址法处理冲突) 1000(ms) 10000(kb) 2698 / 6177 采用除留余数法(H(key)=key %n)建立长度为n的哈希表,处理冲突用开放定址法的线性探测. 输入 第 ...
- react-native 组件整理
好早之前整理的部分组件,不全 怕丢
- 二分(HDU2289 Cup)
贴代码: 题目意思:已知r水的下半径,R水的上半径,H为圆台高度,V为水的体积,求水的高度,如图: 水的高度一定在0-100,所以在这个区间逐步二分,对每次二分出的水的高度,计算相应的体积,看看计算出 ...
- Lua学习链接
Lua捕获 Lua中_G 是个什么鬼 Lua与ObjC的交互
- python语法_模块_os_sys
os模块:提供对此操作系统进行操作的接口 os.getcwd() 获取python运行的工作目录. os.chdir(r'C:\USERs') 修改当前工作目录. os.curdir 返回当前目录 ( ...
- CSS文字的跑马灯特效
上学时同学有个来电带跑马灯的手机,可把我羡慕坏了,可等我买的起手机时,跑马灯不流行了,甚伤萝卜心! 今天就用CSS做个文字的跑马灯特效,缅怀一下本萝卜逝去的青春! 道具:会敲代码的巧手.七窍玲珑心.会 ...