public class DBUtil {
static {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public static Connection getConn() throws SQLException {
return DriverManager.getConnection("jdbc:mysql:///demodb?characterEncoding=utf-8&&serverTimezone=Asia/Shanghai","root","root");
}
public static void close(ResultSet res,PreparedStatement stmt,Connection conn){
if (res !=null){
try {
res.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
if (stmt != null){
try {
stmt.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
if (conn != null){
try {
conn.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
04-24
02-14
820
