数据库时区问题 [英] time zone issue with database

查看:59
本文介绍了数据库时区问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试与 MySQL 数据库建立连接时出现此错误

I'm getting this error while trying to establish connection with database MySQL

java.sql.SQLException:服务器时区值CEST"无法识别或代表多个时区.如果您想利用时区支持,您必须将服务器或 JDBC 驱动程序(通过 serverTimezone 配置属性)配置为使用更具体的时区值.

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.

与MySQL的连接是这样完成的:

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 时区,必须在连接字符串中明确指定服务器时区.

Apparently, MySQL JDBC driver to work with CEST time zone, one has to specify the server timezone explicitly in the connection string.

jdbc:mysql://localhost/vmenginedatabaseT04P?serverTimezone=UTC

这篇关于数据库时区问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆