设为首页 加入收藏

TOP

对于使用JDBC连接mysql数据时The server time zone value '¤¤°ê??·?????'...的异常问题解决。
2019-09-17 19:01:18 】 浏览:44
Tags:对于 使用 JDBC 连接 mysql 数据时 The server time zone value ' ... 异常 问题 解决

相信很多小伙伴和我一样遇到了这类问题,在使用JDBC连接mysql数据库的时候发生SQLException如下所示的异常情况!

java.sql.SQLException: The server time zone value '¤¤°ê¼Ð·Ç®É¶¡' 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.
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at com.ast.service.impl.VboxDataServiceImpl.insertAll(VboxDataServiceImpl.java:34)
    at com.ast.controller.Thread_send.run(Thread_send.java:85)
Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '¤¤°ê¼Ð·Ç®É¶¡' 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.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
    at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132)
    at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2241)
    at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2265)
    at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1319)
    at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:966)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
    ... 7 more

这其实是由于在安装的时候没有选择使用位置,mysql默认使用美国时间,所以得改成我们东八区的时间。

所以应该怎么做呢?

首先网上有很多方法是更改数据库中的 time_zone,如下图:

这个方法只能是解决这一次问题,重启之后依然会报错,还需要再次更改。

最好的方法就是在jdbc配置中添加?serverTimezone=UTC到末尾。

如下图所示:

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Hive基础测试操作 下一篇MongoDB学习(查找文档和其他数据..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目