* jdbc-mysql基础 注册驱动DriverManager.registerDriver:
http://www.cnblogs.com/jizuiku/p/7843416.html
<http://www.cnblogs.com/jizuiku/p/7843416.html>
* JAVA JDBC(MySQL)驱动源码分析(一):
https://blog.csdn.net/brilliancezhou/article/details/5425655
<https://blog.csdn.net/brilliancezhou/article/details/5425655>
* MySQL的JDBC驱动源码解析:
https://blog.csdn.net/c929833623lvcha/article/details/44517245
<https://blog.csdn.net/c929833623lvcha/article/details/44517245>
* 在Java中connection的常用方法及其描述是什么:https://wenda.so.com/q/1364074032061047?src=140
<https://wenda.so.com/q/1364074032061047?src=140>
* jdbc的数据库驱动类DriverManager.getConnection()详解:
https://blog.csdn.net/k_c123456/article/details/78728284
<https://blog.csdn.net/k_c123456/article/details/78728284>
//数据库连接的本质其实就是客户端维持了一个和远程MySQL服务器的一个TCP长连接,并且在此连接上维护了一些信息。
//socket是TCP/IP协议的API。其只是对TCP/IP协议栈操作的抽象(和指向对象的指针类似),形成了几个最基本的函数接口。比如create,listen,accept,connect,read和write等等。
import java.sql.*;public class Test { public static void main(String[] arg)
throws Exception{ String user ="root"; String password = "123456"; String url =
"jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=UTF8";
String driver ="com.mysql.jdbc.Driver"; Connection con = null; //一个封装了TCP长连接 的
数据库长连接对象 Statement stmt = null; //一个封装和管理SQL语句的java对象 ResultSet rSet = null;
//一个封装了数据对象 的 无序集合对象 try{ Class.forName(driver); //加载数据库驱动到JVM中,并实例化为Driver对象
con = DriverManager.getConnection(url, user, password);
//建立TCP数据库长连接,获取Connection对象 stmt = con.createStatement(); //获取SQL管理对象Statement
//stmt.execute("insert into account
values('13542829631','[email protected]','环羽画','123456')"); rSet =
stmt.executeQuery("select * from account"); while(rSet.next()){ System.out
.println(rSet.getString(1)+" "+rSet.getString(2)+" "+rSet.getString(3)); } }
catch(SQLException e){ e.printStackTrace(); }finally{ if(rSet!=null)
rSet.close();if(con!=null) con.close(); if(stmt!=null) stmt.close(); } } }