当前位置: 代码迷 >> 综合 >> 使用新版本mysql-connector-java异常解决
  详细解决方案

使用新版本mysql-connector-java异常解决

热度:30   发布时间:2023-10-17 10:18:56.0

  最近按正常的方法搭建SSM框架,无法正常启动Tomcat出现如下异常信息:

 

com.mysql.cj.core.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)

 

  发现是由于使用了最新的mysql连接jar包(mysql-connector-java-6.0.6)导致的:

  一开始最配置的数据库url信息如下:

      db.url=jdbc:mysql://localhost:3306/permission?useUnicode=true&characterEncoding=UTF-8

  修复方法:数据库连接的url上加上&serverTimezone=GMT

 

  即变更为db.url=jdbc:mysql://localhost:3306/permission?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT

 

  解决掉该问题后启动tomcat,发现又疯狂打印如下日志

 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

Wed Dec 06 21:49:08 CST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification

 

  解决办法:添加&useSSL=false

     db.url=jdbc:mysql://localhost:3306/permission?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT&useSSL=false

 

  接着用mybatis-generator自动生成数据库相关文件时,又出现如下错误:

Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate (default-cli) on project permission: Column name pattern can not be NULL or empty.

 

  解决办法:添加&nullNamePatternMatchesAll=true

 

  最后的数据库连接的地址如下,启动Tomcat正常运行:

jdbc:mysql://localhost:3306/permission?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT&nullNamePatternMatchesAll=true

      OK,完工,可以正常使用了

  相关解决方案