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 ...
随机推荐
- PRTG测试!
http://www.paessler.com/prtg. 我的效果图:
- centos查看apache用的是哪个httpd.conf
httpd -V得到类似如下结果: -D HTTPD_ROOT="/etc/httpd" -D SERVER_CONFIG_FILE="conf/httpd.conf&q ...
- teamviewer quicksupport 插件(下载)
teamviewer quicksupport 插件(下载) teamviewer是一款远程控制软件(免费,比较好的); teamviewer quicksupport是一款支持手机可以被远程控制软件 ...
- ubuntu/deepin 下 Sha 哈 dow 哈 socks 全局配置
1. 安装编译环境 Ubuntu在默认情况下没有提供C/C++的编译环境,因此需要手动安装.如果单独安装gcc以及g++比较麻烦,为了方便,我们直接安装Ubuntu提供的build-essential ...
- boa调试
Cannot access memory at address 0x0 0x400fc7e0 in ?? () 0 0x4014f0dc in wcscasecmp_l () from /lib/li ...
- vs2013新建asp.net web 项目报错,此模板尝试加载组件程序集NuGet Package Manage
打开vs2013,工具->扩展和更新->联机->找到NuGet Package Manager->安装->重新启动vs2013
- 干货分享: 长达250页的Libvirt Qemu KVM的ppt,不实验无真相
下载地址:Libvirt Qemu KVM 教程大全 http://files.cnblogs.com/popsuper1982/LibvirtQemuKVM.pptx 1. 概论 1.1 虚拟化的基 ...
- 微信小程序setData()方法的详解以及对数组/json操作
此篇文章是本人对setData方法的一些理解,是查阅文档和查找一些其他资料综述的,有所不足希望指正! 直接进入正题! 一.setData()方法: 1.参数接受一个对象,以key,value的形式表示 ...
- 美团App用户界面分析
关于美团 美团网成立于2010年,合并前是中国销售额最大的独立团购 App.美团网2014年全年交易额突破460亿元,较去年增长180%以上,市场份额占比超60%,用户数超2亿~ 美团 App 用户界 ...
- 推荐几个牛逼的 IDEA 插件,还带动图!
阅读本文大概需要 2.3 分钟. 作者:纪莫, cnblogs.com/jimoer 这里只是推荐一下好用的插件,具体的使用方法不一一详细介绍. JRebel for IntelliJ 一款热部署插件 ...