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 ...
随机推荐
- 【工作手札】Nginx接口代理可跨域
接口代理nginx配置 location /api/ { proxy_set_header Host api.shenjian.io; proxy_set_header X-Forwarded-For ...
- js的算法题
1.统计一个字符串中出现最多的字母 给出一个字符串,统计出现次数最多的字母.如:“wqeqwhixswiqhdxsq”,其中出现最多的是q. js算法的实现 function findMax(str) ...
- libevent入门介绍
libevent是之前看到的一个别人推荐的清凉级网络库,我就想了解一下它.今天下载到了一个人写的剖析系列,从结构和源码方面进行了简要分析.只是这个分析文章是2010年的,有点过时了(跟现在的libev ...
- CentOS 编译安装 Redis (实测 笔记 Centos 7.3 + redis 3.2.8)
环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.准备 1.1 显示系统版 ...
- cadence元件放置方法
在导入网表之后,需要放置元件,介绍几种常见的放置元件的方法和常用的几种元件操作方法.
- pycharm 中 django 导入静态文件不提示补全
File—>setting----->Languages & Frameworks ------> Python Template Languages ------> ...
- js中的cookie
cookie就是一个存放数据的东西,存储量很小4kb,存放在客户端上和应用设备上. 应用场景 用户注册,用户登录,购物车. Chrome浏览器在计算机中存放cookie的位置 C:\Users\Adm ...
- Java作业七(2017-10-30)
/*造人*/ public class Tman { public int id; public String name; public int age; public String city; pu ...
- 坦白说bug
安卓收藏他发的图片就可以在收藏里看到了哦 苹果直接搜索聊天记录就行了哦(人 •͈ᴗ•͈)۶♡♡比心心
- PHPWord导出word文档
最近接了个把数据导出到word文档的需求,之前一直都是使用PHPExcel库导出excel的,还是头次接到导出到word文档的需求,我想既然有PHPExcel,那么肯定也会有PHPWord库吧,在网上 ...