• 对于使用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到末尾。

    如下图所示:

  • 相关阅读:
    springboot动态修改日志级别
    加密算法之RSA算法
    关于 BeanDefinitionOverrideException的解析
    Hive基础知识总结
    Java中的字符串替换:replace/replaceAll/StringTemplate
    xxl-job简介&整体架构设计
    java启动springboot jar包后台不挂断运行
    java自定义线程名称
    idea2019.2.2版本激活
    Log4j的MDC机制如何在线程池中使用
  • 原文地址:https://www.cnblogs.com/mzxiaoze/p/10683431.html
Copyright © 2020-2023  润新知