一些背景知识:
我有一个运行在Tomcat7上的Java1.6Webapp,数据库是MySQL 5.5。在此之前,我使用Mysql JDBC驱动程序5.1.23连接到数据库。一切都成功了。我最近升级到了Mysql JDBC驱动程序5.1.33。升级后,Tomcat会在启动应用程序时抛出此错误。
WARNING: Unexpected exception resolving reference
java.sql.SQLException: The server timezone value 'UTC' is unrecognized or represents
more than one timezone. You must configure either the server or JDBC driver (via
the serverTimezone configuration property) to use a more specifc timezone value if
you want to utilize timezone support.
为什么会发生这种情况?
发布于 2014-12-04 00:15:49
显然,要使UTC驱动程序5.1.33版使用MySQL时区,必须在连接字符串中显式指定serverTimezone
。
jdbc:mysql://localhost/db?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
发布于 2016-10-26 01:14:22
我已经通过配置MySQL解决了这个问题。
SET GLOBAL time_zone = '+3:00';
发布于 2016-06-24 13:09:38
如果您使用的是Maven,那么只需在pom.xml
中设置另一个MySQL连接器版本(我也有同样的错误,所以我从6.0.2改为5.1.39)
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
如另一答案所述,此问题已在6.0.3或更高版本中修复,因此您可以使用更新版本:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.3</version>
</dependency>
保存pom.xml
文件后,Maven将自动重新生成项目。
https://stackoverflow.com/questions/26515700
复制相似问题