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);
}
}
}
Java 编写DBUtil
最新推荐文章于 2024-08-19 16:01:20 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)