I'm getting this error while trying to establish connection with database MySQL
java.sql.SQLException: The server time zone value 'CEST' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
connection with MySQL is done this way:
private String CONN_STRING = "jdbc:mysql://localhost:3306/vmenginedatabaseT04P/"; // "jdbc:mysql://localhost:3306/vm_database_1";
private boolean connected ;
private Connection connection;
public boolean isConnected() {
return connected;
}
public Connection Connect() {
Connection conn = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection(CONN_STRING,USERNAME,PASSWORD);
System.out.println("Connected");
connected = true;
return conn;
} catch (SQLException e) {
System.err.println(e);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
显然,MySQL JDBC驱动程序要使用CEST时区,必须在连接字符串中显式指定服务器时区。
jdbc:mysql://localhost/vmenginedatabaseT04P?serverTimezone=UTC
将serverTimezone=UTC
添加到您的CONN_STRING
,如下所示:
private String CONN_STRING = "jdbc:mysql://localhost:3306/vmenginedatabaseT04P?serverTimezone=UTC"; // "jdbc:mysql://localhost:3306/vm_database_1";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.