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

posted on 2020-11-10 18:37  吴。。。。。  阅读(38)  评论(0)    收藏  举报