Class.forName("com.mysql.jdbc.Driver");
2.获取连接
Connection conn=DriverMAnager.getConnection(url,username,password);
3.获取sql执行对象
PreapareStatment pst=conn.prepareStatement("sql");
4.执行sql
ResultSet rs=pst.executeQuery(); 查询
int i = pst.executeUpdate(); 增删改
5.查看执行结果
rs
i
6.关闭资源
public static void closeDb(ResultSet rs,PreparedStatement pst,Connection connection){
if(null != rs){
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(null != pst){
try {
pst.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(null != connection){
try {
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}