protected Connection coon = null;
protected PreparedStatement pstmt = null;
protected ResultSet rs = null;
public Connection getConnection() {
try {
String url = "jdbc:mysql://localhost:3306/my_db?useUnicode=true&characterEncoding=utf-8";
String user = "sa";
String password = "123456";
coon = DriverManager.getConnection(url, user, password);
} catch (Exception e) {
e.printStackTrace();
}
return coon;
}
public void closeAll(Connection coon, PreparedStatement pstmt, ResultSet rs) {
try {
if (rs != null) {
rs.close();
}
if (coon != null) {
coon.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
原文:https://www.cnblogs.com/OfflineBoy/p/14260104.html