JDBC全部分析
2.1、搭建实验环境
1、在mysql中创建一个库,并创建user表和插入表的数据。
SQL脚本如下:
1 create database jdbcStudy character set utf8 collate utf8_general_ci;
2
3 use jdbcStudy;
4
5 create table users(
6 id int primary key,
7 name varchar(40),
8 password varchar(40),
9 email varchar(60),
10 birthday date
11 );
12
13 insert into users(id,name,password,email,birthday) values(1,'zhansan','123456','zs@sina.com','1980-12-04');
14 insert into users(id,name,password,email,birthday) values(2,'lisi','123456','lisi@sina.com','1981-12-04');
15 insert into users(id,name,password,email,birthday) values(3,'wangwu','123456','wangwu@sina.com','1979-12-04');
2、新建一个Java工程,并导入数据驱动。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAARcAAAC3CAIAAAC32o3ZAAAcz0lEQVR4nO2df2wU55nHtz+4/Os/UBv+qERToEhIdYRySN0/4lN/xNBI17vmriLRReZEmCZS1F5cnerogmxDiRxClSnFiasUG+6ayHB1z0DZs1O4NU1soRaFTVI4lxVZJ9Cza69/YIhZU9L3/pjdmffH87wzszO7O+N9Pnpl7c68877vjN/vPM/77rzPJBhBEAEoFAqJWreBIOINqYgggkIqIoighK+iXC7d3tfX1Jdu7+vL5dLhFk4QESRkFeVy6aZ0uiWdHhkZOXLk5019aRISseIJqqJ3Bp61E2OsPZ1u6Uv3pfvSufZ0uq+lPd3S3hdOS0MmayYTRqrWrQiXlJFImtlat6IOCaSizC+eFb+2NfWlR0ZG0umW9r6m9r6mpvamppY++OAw/uUpI8FLIWsm+TKlryJ+VOQ0NWsmExxCASmD2yPXy+1Ea3XylClvX5eUOxWuOrsNYkEpA25V1kwKWaHDXSriS0VqjzzlqKi784Xuzhe6O7vu/Kn3zp96l3Iv59958dq53X84+Ux7X197X7q9r729pamlvaWppb29vR0uJZQbp1CI9e9yvmtrKF9FzlFi3+KrE+QtdcGUAbWKPyJrJq2PPg2mj0vKNcKphLvtOM2xhGIYQEuyZjKZdO5U4OHceTn77ROEd8t3x8iDqiidTnd1dYG7Xvi3H+378Xl24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B+cwJkV/8J69fErdzW8gnrEvCVBFjLJ/Pm6Z55coVLNuZ9s2FqUFN6m1Zq6mFXzZaXENkv7DYkZcS28AliIKqgJQhOYucYKDtZIvqmpBVxBibnJzs7Oycm5sDs/2qfXNh4oidBlobNQk4vigbWz3FD0L8EiC2gfvyb2kZqmhVStmw7aSi+iZkFc3Ozupt0UDrpsK4aaWB1sbCRA+YpjJdsIpsT67Um4Hv7ivDwd7P6QhQixqpi9tOKqpvwlTRzMyM67jotafXFca7CuNdA62N1gc14RJirDSrILhV8ncltoG3IArcwEjx3Fy2k4rqmmrP0fW2fK6QaRtobSxkOsCklxBjRZ+N67LydzTMoscgCo498ji7wNVJswt1SbV/L3rpW2sGWhsLmTYwuUuIIKJHDZ5d6DW+qElVbgxBBKdOnqMjiApCKiKIoJCKCCIopCKCCAqpiCCCUigU/h+0rAPTVwg+0gAAAABJRU5ErkJggg==" alt="" />
3、编写程序从user表中读取数据,并打印在命令行窗口中。
具体代码如下:
1 package me.gacl.demo;
2 import java.sql.Connection;
3 import java.sql.DriverManager;
4 import java.sql.ResultSet;
5 import java.sql.Statement;
6
7 public class JdbcFirstDemo {
8
9 public static void main(String[] args) throws Exception {
10 //要连接的数据库URL
11 String url = "jdbc:mysql://localhost:3306/jdbcStudy";
12 //连接的数据库时使用的用户名
13 String username = "root";
14 //连接的数据库时使用的密码
15 String password = "XDP";
16
17 //1.加载驱动
18 //DriverManager.registerDriver(new com.mysql.jdbc.Driver());不推荐使用这种方式来加载驱动
19 Class.forName("com.mysql.jdbc.Driver");//推荐使用这种方式来加载驱动
20 //2.获取与数据库的链接
21 Connection conn = DriverManager.getConnection(url, username, password);
22
23 //3.获取用于向数据库发送sql语句的statement
24 Statement st = conn.createStatement();
25
26 String sql = "select id,name,password,email,birthday from users";
27 //4.向数据库发sql,并获取代表结果集的resultset
28 ResultSet rs = st.executeQuery(sql);
29
30 //5.取出结果集的数据
31 while(rs.next()){
32 System.out.println("id=" + rs.getObject("id"));
33 System.out.println("name=" + rs.getObject("name"));
34 System.out.println("password=" + rs.getObject("password"));
35 System.out.println("email=" + rs.getObject("email"));
36 System.out.println("birthday=" + rs.getObject("birthday"));
37 }
38
39 //6.关闭链接,释放资源
40 rs.close();
41 st.close();
42 conn.close();
43 }
44 }
运行结果如下:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQEAAAF/CAIAAADGpusbAAAgAElEQVR4nO2d+5McV3XH+9+x9FN+USnziyqVKqfgB1dEJUixCV7bYmyBgQITQYCKXypWXgQM4NgCU/YSwJYRstfYTCiLUHIsCMEuSS5pHVVtVYJju/yIZa8RXs2+pvNDv+7jnHPv7e6dnZn7/dSWPerue/t29/n2Pbf7ntPJ/Pz89555CX/4i/YvmQcgbpJlAOIGGgCxAw2A2DE1sLi4uN3uGQggwuvV+iEntvWPVoRjwSQeeHm90phQldDWmUzUE9pWpZPFJB54dr222yC3kxbFkCxDAJNGdr2GYDgcDofNlZAYApg/NjPf2z9/bGb+2G3z8186Pn/k+PFjxxeOH1/45fFfnl44fX7h9KU2ruNY4BTANx9aOPHcxRPPXfzmQwsjaZEbCICkiQwsDfT2n18epGn65mCg/qVpeurMYvZ74fQfWrqg24ysgXu+/dMnnn3xiWdffPLZF5949sV7vv3TkTVMILtemwrX3/nkNZ89I/9df+eTm9NO7Q4hMezgWG8m08ArL51bvO/eF/Z+aPG+e1956VyapqfOXHxzMHhrWmTACeC1l3/7m+/f9Jvv3/S5e+aPPXb6wcdOP/jY6WOPnf7cPfMn7/7Ib75/02sv/3bETS3JBLChc81n/v1vDtwr/13zmX/fiIMaMjA10Dsyc355MEzTxfsOv377rVfu/Orrt9+6eN/hzXR46vmLb60O3l5d3QINnJ3dlcycsJefmCEXtwGngYsLX7m48JWZOx64+/5n7r7/mbvuf+bu4u/GOx7I1rbXCu7AaWgN3P7rfbd+7dzlde5v361fu+b2X2+LRSo8/YnkE08HljlY4FyoEioDWwO3nV8ebAzTF/Z+6L09e9/f85H39ux94a/2bAyHp56/+H+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71tfo+60VucNamP0PpB4Q8+pat0ypjA9/DLU+NOrVbOZdUME4cGqCNZuQasCOp+Kgr45aq7rRm8JKf/0RXzh6zWNZnwqrcKq5vYWvOmtDTYhuqxlsHF5EGxqQfEDRgmQLvOpnBK418Ib+D8/PH/YRCFWJaRQ1nXRCvfcrLwD/VmGwl+GiAUftINUDfI3Wf3ixLROBmj/NqPVL10YDfECmgbP1W1RFAUY6WALPxJFt/hlsD8luScA3IjjWrPdOb6XS7Zly8I1eC+cgqEJcpcy/OfTqB2i/dmVY1CXbTa5StfGo1YPZ5XNqNhNrIz9kmH+U7+x/91aTh0xiv94VcCXUeibJdv7pbqmIPX6WOLuVW0ZcoYCe+LZteDUwr7QTDg2kjIg3UGnOC6ScaDYTMmQFRMf0aMKdgAKAz/RoAQAYaALEDDYDYgQZA7Pw/pe9H154HymMAAAAASUVORK5CYII=" alt="" />
2.2、DriverManager类讲解
Jdbc程序中的DriverManager用于加载驱动,并创建与数据库的链接,这个API的常用方法:
- DriverManager.registerDriver(new Driver())
- DriverManager.getConnection(url, user, password),
注意:在实际开发中并不推荐采用registerDriver方法注册驱动。原因有二:
1、查看Driver的源代码可以看到,如果采用此种方式,会导致驱动程序注册两次,也就是在内存中会有两个Driver对象。
2、程序依赖mysql的api,脱离mysql的jar包,程序将无法编译,将来程序切换底层数据库将会非常麻烦。
推荐方式:Class.forName("com.mysql.jdbc.Driver");
采用此种方式不会导致驱动对象在内存中重复出现,并且采用此种方式,程序仅仅只需要一个字符串,不需要依赖具体的驱动,使程序的灵活性更高。
2.3、数据库URL讲解
URL用于标识数据库的位置,通过URL地址告诉JDBC程序连接哪个数据库,URL的写法为:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAhkAAAByCAIAAABx1FRsAAASVUlEQVR4nO2dTY7ruBHHdRYfQAcwfAoBfQWtvPMJ+gbu3vR+LtBeBD7FGwQZZBXvM5kBkkUQBJiXGXQW+uJHFVkURYm0/j8Qgzd+lERWFfkni7Jf9QUA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Sa0qmPbOWTPphNrIPMLpTg5b0CvFudtA2CL8NIvD6EVpSIotqiZlO1ecFalQPUTW++RqWV1VLdlqykTWK0ZLb5dBZwzq2nS5htGSauaSWIabO0ByXhyy15MOa5adU6mBBfl/SW+bVEkvLs9zP/BC/8Oj7QZpvH9CSMln4neBx2PdfaGKmEu2rttb5wRj9Qe8vZaYlm1kjby2hNmeTllhyO85i+nQWriWO5i2yL5n5AyqR/pJoifL1nX6NMn4blP0G7vTatPLqsENL2IOQmb8WDC0pkaW0RBuBylLIM8aIH4lTP+fWTVRJoiX6j6QKv3a3rTW20JKQF6l7S1iCQX+RzTjPnz9lc9butGSS/8Coiy8x/hJ9v0SLW/MlXSW0plfYzYBnvoeobRNpUYeW7IhF/v2Shv72rLvM+gFHR0m4L6F+ECJba2yhJXFFmaqW+j1gSelfmTM+t770nrqk0RL7p89GVRbpsWYc6zeArb/l7jnnB78/oCVlgn9X8dlKeVqy75JwX1JsgZaUCLTk2Qq0pKwCLbELtKREoCXPVqAlZRVoiV2gJSUCLXm2Ai0pq0BL7AItKRGRlhREQM+fl4h42K/RNmS2O/73xx9btz0hC8YtWAE4DAAAQCzQEgAAALFASwAAAMQCLQEAABALtAQAAEAs0BIAAACxQEsAAADE8n/0TD/0Jgby6gAAAABJRU5ErkJggg==" alt="" />
常用数据库URL地址的写法:
- Oracle写法:jdbc:oracle:thin:@localhost:1521:sid
- SqlServer写法:jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=sid
- MySql写法:jdbc:mysql://localhost:3306/sid
如果连接的是本地的Mysql数据库,并且连接使用的端口是3306,那么的url地址可以简写为: jdbc:mysql:///数据库
2.4、Connection类讲解
Jdbc程序中的Connection,它用于代表数据库的链接,Collection是数据库编程中最重要的一个对象,客户端与数据库所有交互都是通过connection对象完成的,这个对象的常用方法:
- createStatement():创建向数据库发送sql的statement对象。
- prepareStatement(sql) :创建向数据库发送预编译sql的PrepareSatement对象。
- prepareCall(sql):创建执行存储过程的callableStatement对象。
- setAutoCommit(boolean autoCommit):设置事务是否自动提交。
- commit() :在链接上提交事务。
- rollback() :在此链接上回滚事务。
2.5、Statement类讲解
Jdbc程序中的Statement对象用于向数据库发送SQL语句, Statement对象常用方法:
- executeQuery(String sql) :用于向数据发送查询语句。
- executeUpdate(String sql):用于向数据库发送insert、update或delete语句
- execute(String sql):用于向数据库发送任意sql语句
- addBatch(String sql) :把多条sql语句放到一个批处理中。
- executeBatch():向数据库发送一批sql语句执行。
2.6、ResultSet类讲解
Jdbc程序中的ResultSet用于代表Sql语句的执行结果。Resultset封装执行结果时,采用的类似于表格的方式。ResultSet 对象维护了一个指向表格数据行的游标,初始的时候,游标在第一行之前,调用ResultSet.next() 方法,可以使游标指向具体的数据行,进行调用方法获取该行的数据。
ResultSet既然用于封装执行结果的,所以该对象提供的都是用于获取数据的get方法:
获取任意类型的数据
getObject(int index)
getObject(string columnName)
获取指定类型的数据,例如:
getString(int index)
getString(String columnName)
ResultSet还提供了对结果集进行滚动的方法:
- next():移动到下一行
- Previous():移动到前一行
- absolute(int row):移动到指定行
- beforeFirst():移动resultSet的最前面。
- afterLast() :移动到resultSet的最后面。
2.7、释放资源
Jdbc程序运行完后,切记要释放程序在运行过程中,创建的那些与数据库进行交互的对象,这些对象通常是ResultSet, Statement和Connection对象,特别是Connection对象,它是非常稀有的资源,用完后必须马上释放,如果Connection不能及时、正确的关闭,极易导致系统宕机。Connection的使用原则是尽量晚创建,尽量早的释放。
为确保资源释放代码能运行,资源释放代码也一定要放在finally语句中。
JDBC全部分析的更多相关文章
- JDBC性能分析与优化
JDBC性能分析与优化V1.0http://www.docin.com/p-758600080.html
- JDBC ResultSet分析
JDBC1.0 .JDBC2.0 .JDBC3.0 中分别用以下方法创建Statement . JDBC1.0 : createStatement() JDBC2.0 : createStatemen ...
- JAVA JDBC 元数据分析小结
纯干货: 获取数据库名称: /** * 获取数据库的名称 */ public void getDataBaseName() throws Exception { Connection con = DS ...
- JDBC缺点分析
* JDBC代码繁琐,每一次JDBC都需要编写“同样”的六步. * sql不能配置,在JDBC编程中sql语句是写在java源程序当中的,sql语句经常会发生改变(业务发生了改变),sql改变之后,需 ...
- MyBatis+Hibernate+JDBC对比分析
MyBatis目前作为持久层,用的最多,因为它符合互联网开发的变动性,实际开发中需求总会有这样的,那样的变动,MyBatis虽然没有Hibernate那么全自动化,而且对于开发人员的sql能力要求比较 ...
- java jdbc preparedstatement 分析
https://blog.csdn.net/xiong9999/article/details/54137326
- jdbc操作数据库
JDBC全称为:Java DataBase Connectivity(java数据库连接). SUN公司为了简化.统一对数据库的操作,定义了一套Java操作数据库的规范,称之为JDBC. 学习JD ...
- MySQL数据库学习笔记(十)----JDBC事务处理、封装JDBC工具类
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
- 初学JDBC,最简单示例
一.下载相应数据库驱动jar包,添加到项目中 二.注册驱动,数据库驱动只加入到classpath中是还不行的,还要在使用的时候注册一下,就像安装驱动软件,只拷贝到硬盘还不行,需要安装一下 Driver ...
随机推荐
- iOS优化策略
之前写的一系列文章或者小经验一直没有时间去整理放在博客上,今天整理出来,之前是写在作业部落,语法是markdown,点击链接浏览,仅供参考,希望对你有帮助. https://www.zybuluo.c ...
- HBase协处理器同步二级索引到Solr
一. 背景二. 什么是HBase的协处理器三. HBase协处理器同步数据到Solr四. 添加协处理器五. 测试六. 协处理器动态加载 一. 背景 在实际生产中,HBase往往不能满足多维度分析,我们 ...
- iOS 中代码获取当前版本号
[1]概念 iOS的版本号,一个叫做Version,一个叫做Build,这两个值都可以在Xcode 中选中target,点击“Summary”后看到. Version在plist文件中的key是“CF ...
- SET IDENTITY_INSERT 和 DBCC CHECKIDENT
SET IDENTITY_INSERT (Transact-SQL) Allows explicit values to be inserted into the identity column of ...
- YTU 2577: 小数计算——结构体
2577: 小数计算--结构体 时间限制: 1 Sec 内存限制: 128 MB 提交: 978 解决: 647 题目描述 小数可以看成是一个点和两个数组成的,因此可以定义成一个小数的结构体,现在 ...
- MYSQL进阶学习笔记五:MySQL函数的创建!(视频序号:进阶_13)
知识点六:MySQL函数的创建(13) 内置函数: 自定义函数: 首先查看是否已经开启了创建函数的功能: SHOW VARIABLES LIKE ‘%fun%’; 如果变量的值是OFF,那么需要开启 ...
- WebStorm配置SVN
下载SVN客户端管理工具TortoiseSVN-1.8.5.25224-x64-svn-1.8.8,选择合适的Windows版本 配置项目目录,对应的VCS为Subversion 设置Subversi ...
- SPOJ:String Play (?)
String Play Milo has a string S of length L. Tutu picks a random prefix and Mota picks a random suff ...
- 【Cocos2d-HTML5 开发之一】新建HTML5项目及简单阐述与cocos2d/x引擎关系
真的是有一段时间没写博了,这段时间呢,发生的事情真的挺多,另外自己呢也闲来做了一些自己的喜欢的东西,主要做的还是基于Mac系统的Cocoa框架的各种编辑器吧.(对了,今年初也出了自己第二本书<i ...
- rtmplib rtmp协议过程分析
转自:http://chenzhenianqing.cn/articles/1009.html 写的很好,收藏如下,向作者致敬! 没事碰到了librtmp库,这个库是ffmpeg的依赖库,用来接收,发 ...