正如标题所说,我试图通过单例设计模式连接到我的数据库,但它似乎没有连接,我找不到问题所在。
public class DatabaseConnection {
private static Connection conn;
static{
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/athentication", "root", "");
System.out.println("connected");
}catch(SQLException e){
System.out.println(e);
}
}
public static Connection getCon(){
return conn;
}
}我也尝试过通过main验证连接,但控制台中没有显示“已连接”消息,我也得到了这样的消息:
java.sql.SQLException:服务器时区值“”马来半岛标准时间“”无法识别或表示多个时区。“”如果要利用时区支持,则必须配置服务器或JDBC驱动程序(通过serverTimezone配置属性)以使用更具体的时区值。
发布于 2018-12-06 20:01:42
尝试将时区附加到连接字符串。
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/athentication?serverTimezone=" + TimeZone.getDefault().getID(), "root", "");https://stackoverflow.com/questions/53650812
复制相似问题