JDBC技术

JDBC简介

   ·什么是JDBC

  

   ·什么是数据库驱动程序

  

   ·程序操作数据库流程

  

JDBC3.0接口中常见接口与类的介绍

   ·Driver接口

  

   ·DriverManager类

  

  常用方法:  

  JDBC URL:  

   ·Connection接口

  

  常用方法:

    

 ·statement接口

  

  常用方法:

    

 ·preparedStatement接口

  

  常用方法:

    

   ·ResultSet接口

  ResultSet通过检索不同类型字段的方法

  常用方法:

    

  ResultSet对结果集进行滚动的方法:

    

   ·CallableStatement接口

  

JDBC的使用步骤

  加载数据库驱动程序 —>建立数据库连接Connection—>创建执行SQL的语句Statement—>处理执行结果ResultSet—>释放资源

 ·下载数据库驱动

  

  

   ·创建项目添加驱动

  

 通过Statement向表中插入数据

 ·注册驱动

Class.forName("com.mysql.jdbc.Driver");

 ·获取连接

Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/bjsxt?useUnicode=true&characterEncoding=utf-8","root", "root");

 ·执行SQL

String sql = "insert into departments values(default,'"+department_name+"'"+location_id+");
Statement state = conn.createStatement();

 ·释放资源

if(state != null){
try {
state.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn != null){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

  

原文地址:https://www.cnblogs.com/zqfdgzrc/p/10694578.html