JDBC

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

原文地址:https://www.cnblogs.com/wuyiping/p/13955320.html