package myweb.db;
import java.sql.*;
/**负责创建数据库连接*/
public class DBConnector {
/**打开一个数据库连接,如果连接失败,返回null*/
public static Connection open() {
try {
//1.加载驱动程序
Class.forName("com.mysql.cj.jdbc.Driver");
//2.填写连接参数,获取连接对象
return DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test?serverTimezone=UTC"
, "root", "123456");
}catch(Exception e) {
e.printStackTrace();
return null;
}
}
public static void main(String[] args) {
System.out.println(DBConnector.open());
}
}
java连接数据库设置时区
最新推荐文章于 2024-04-12 17:08:45 发布