如何通过JDBC访问数据库

news/2024/5/19 0:01:38 标签: jdbc
  1. jdbc-mysql基础 注册驱动DriverManager.registerDriver:http://www.cnblogs.com/jizuiku/p/7843416.html
  2. JAVA JDBC(MySQL)驱动源码分析(一):https://blog.csdn.net/brilliancezhou/article/details/5425655
  3. MySQL的JDBC驱动源码解析:https://blog.csdn.net/c929833623lvcha/article/details/44517245
  4. 在Java中connection的常用方法及其描述是什么:https://wenda.so.com/q/1364074032061047?src=140
  5. jdbc的数据库驱动类DriverManager.getConnection()详解: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','1393180812@qq.com','环羽画','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();
         }

     }
}

http://www.niftyadmin.cn/n/1098275.html

相关文章

Codeforces Educational 38 D. Buy a Ticket ( 建图+堆优化Dij

题目描述 Musicians of a popular band “Flayer” have announced that they are going to “make their exit” with a world tour. Of course, they will visit Berland as well. There are n cities in Berland. People can travel between cities using two-directional…

Windows程序内部运行原理

Windows程序内部运行原理 一、基本原理 1、Windows应用程序,操作系统,计算机硬件之间的相互关系 一个例子: 汽车厂家生产汽车好比应用程序创建窗口,用户使用汽车好比操作系统管理窗口,某种汽车在销售前就指定好了修…

吞吐量测试与iPerf的使用

一、吞吐量介绍 1.上行吞吐量测试方法 手机作为client端,PC为server端 2.下行吞吐量测试方法 手机作为server端,PC作为client端 什么是WiFI吞吐量? 网络中的数据是由一个个数据包组成,防火墙对每个数据包的处理要耗费资源。吞吐量是指在没有…

Codeforces Educational 38 C. Constructing Tests ( 构造

题目描述 Let’s denote a m-free matrix as a binary (that is, consisting of only 1’s and 0’s) matrix such that every square submatrix of size m  m of this matrix contains at least one zero. Consider the following problem: You are given two integers n…

vector 向量容器

http://blog.163.com/zhoumhan_0351/blog/static/3995422720102251346407/ 一、技术原理 vector 容器是一个线性结构,用 3 个指针存放向量的起始字节位置、当前最后一个向量元素的末尾字节和整个容器所占用的内存空间的末尾字节,如图所示,3 …

无线射频专题《射频合规,2.4GHz WIFI测试指标详解》

目录 引言 Transmitter Power 发送功率 Transmit Spectrum Mask 发送信号频谱模版 Frequency Error 频率误差 EVM 矢量误差幅度 Band Edges and harmonics 频带边缘以及谐波 Spectral Flatness 频谱平坦度 Power On/Off Ramp TX上升/下降时间(发射加电与掉电坡度&am…

Java设计模式及之适配器模式

###简介 适配器模式也称为变压模式,它是把一个类的接口转换成客户端所期望的另一种接口,从而使得原本因接口不匹配而无法一起工作的两个类能够一起工作。

Codeforces Educational 38 B. Run For Your Prize

题目描述 You and your friend are participating in a TV show “Run For Your Prize”. At the start of the show n prizes are located on a straight line. i-th prize is located at position ai. Positions of all prizes are distinct. You start at position 1, you…