private static Connection connection;
private static final String URL = "jdbc:mysql://localhost:3306/test?serverTimezone=GMT";
private static final String USER = "root";
private static final String PASSWORD = "123456";
public Connection getConnection() {
try {
// 加载数据库驱动
Class.forName("com.mysql.cj.jdbc.Driver");
// 获取数据库连接
connection = DriverManager.getConnection(URL, USER, PASSWORD);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
return connection;
}