• SQL问题:com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value


    问题描述:

    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.
    FATAL ERROR in native method: JDWP on checking for an interface, jvmtiError=JVMTI_ERROR_WRONG_PHASE(112)
        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(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:247)
        at com.java.mysql.test.TestDB.getConnection(TestDB.java:22)
        at com.java.mysql.test.TestDB.runTest(TestDB.java:26)
        at com.java.mysql.test.TestDB.main(TestDB.java:45)
    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(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        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:2243)
        at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2267)
        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)
        ... 8 more
    JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on checking for an interface [util.c:1313]

    解决办法:数据库url中地址要配置“serverTimezone=UTC”

     

    扩展:MySQL jdbc 6.0 版本以上必须配置“serverTimezone”参数

              UTC代表的是全球标准时间

              若我们使用的时间是北京时区也就是东八区,领先UTC八个小时。url的时区使用中国标准时间。也是就serverTimezone=Asia/Shanghai

     

    作者:zhangshuai
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    遮罩层点击空白退出代码
    不同浏览器的margin值与padding值
    让div自适应浏览器窗口居中显示
    导航相关(下方导航指示条居中)
    CSS相邻兄弟选择器
    使用font-size:0去掉inline-block元素之间的空隙
    box-sizing属性
    常见浏览器兼容性问题
    秋季编程总结
    POJ 1193 内存分配
  • 原文地址:https://www.cnblogs.com/zhangshaui/p/14818818.html
Copyright © 2020-2023  润新知