首页 > 数据库技术 > 详细

Jdbc

时间:2019-11-28 23:09:43      阅读:120      评论:0      收藏:0      [点我收藏+]

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);

 

 

Jdbc

原文:https://www.cnblogs.com/ream/p/11954549.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!