zoukankan      html  css  js  c++  java
  • Java连接MySql报错—— com.mysql.cj.exceptions.InvalidConnectionAttributeException

    详细报错

    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

  • 相关阅读:
    线程笔记
    值类型与引用类型
    abstract抽象 抽象方法 不能有实现{} 0907
    接口
    结构
    XML初探
    javaScript中为什么会有变量提升?
    Windows 7实现自动登录(本地账户和域账户)
    WCF 提示 "由于正在读取的 XML 数据的嵌套级比配额所允许的多,因此已超出最大读取深度 (32)" 的解决办法
    也来安个家!
  • 原文地址:https://www.cnblogs.com/it-mh/p/11205323.html
Copyright © 2011-2022 走看看