JDBC

时间:2020-11-16 13:44:12   收藏:0   阅读:24

1.加载驱动
 Class.forName(driver_class);
2.创建数据库连接
DriverManager.getConnection(url,user,password);
3.创建PreparedStatement
  PreparedStatement ps=connection.prepareStatement(sql);
4.执行sql语句
  rs=ps.executeQuery();
5.处理结果集
  while (rs.next()){
rs.getObject();
}
6关闭连接(资源从内由外关闭)
  

/从内到外关闭
if (resultSet!=null){
resultSet.close();
}
if (preparedStatement!=null){
preparedStatement.close();
}
if (connection!=null){
connection.close();
}

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!