简体   繁体   English

数据库的时区问题

[英]time zone issue with database

I'm getting this error while trying to establish connection with database MySQL 尝试与数据库MySQL建立连接时出现此错误

java.sql.SQLException: The server time zone value 'CEST' is unrecognized or represents more than one time zone. java.sql.SQLException:服务器时区值'CEST'无法识别或代表多个时区。 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. 如果要利用时区支持,则必须配置服务器或JDBC驱动程序(通过serverTimezone配置属性)以使用更特定的时区值。

connection with MySQL is done this way: 与MySQL的连接是通过以下方式完成的:

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";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM