JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口组成
JDBC 编程的六个步骤:
使用前需要导入ojdbc.jar包
// 1.注册驱动
Class.forName("com.mysql.jdbc.Driver");
// 2.连接数据库
Connection connection = DriverManager.getConnection(url:"jdbc:mysql:///user",user:"root",password:"root");
// 3.创建搬运工 statement
Statement statement = connection.createstatementc();
// 4. 通过 Statement 对象执行SQl语句
statement.excute(sql:"insert into 表名 (值一,值二,……)values (值一,值二,……)");// 没有结果集
statement.excuteQuery(sql""insert into 表名 (值一,值二,……)values (值一,值二,……)");// 有结果集
// 5.处理结果集
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
// 6.关闭结果集
statement.execute(sql);
原文:https://www.cnblogs.com/ream/p/11954549.html