mysql-connector-java 升级到 8.0.11 会更改从数据库中检索到的所有日期值 [英] mysql-connector-java upgrade to 8.0.11 changes all the date values retrieved from the db

查看:54
本文介绍了mysql-connector-java 升级到 8.0.11 会更改从数据库中检索到的所有日期值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 Spring 项目,mysql-connector-java 已从 6.0.6 迁移到 8.0.11.

For a Spring project, the mysql-connector-java has been migrated from 6.0.6 to 8.0.11.

因此对于 8.0.11 问题如下:

Thus with 8.0.11 the problem is the following:

Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: 
The server time zone value 'PET' 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.

在做研究之后

解决方案是更改URL(我不想返回到以前的版本)

the solution is change the URL (I don't want return to a previous release)

  • 来自:mysql.jdbcUrl = jdbc:mysql://localhost:3306/web_v01?useSSL=false
  • 到:mysql.jdbcUrl = jdbc:mysql://localhost:3306/web_v01?useSSL=false&ser​​verTimezone=UTC

观察添加&ser​​verTimezone=UTC

在我的数据库中,我有以下内容:

In my DB I have the following:

mysql> select * from persona;
+-----+--------------+-------------+------------+
| id  | nombre       | apellido    | fecha      |
+-----+--------------+-------------+------------+
...
| 088 | Something    | Something   | 1981-07-06 |
...
+-----+--------------+-------------+------------+

Spring 应用程序通过 RowMapper 从数据库中检索时,我可以确认 rs.getDate("fecha") 返回1981-07-05(观察天数减一,不对正确)

When the Spring application does a retrieve from the db through the RowMapper<Persona> I can confirm that rs.getDate("fecha") returns 1981-07-05 (observe the day has been decreased by one, it is not correct)

如果 mysql-connector-java 返回到 6.0.6 并且因此 mysql.jdbcUrl = jdbc:mysql://localhost:3306/web_v01?useSSL=false (no serverTimezone=UTC) rs.getDate("fecha") 返回 1981-07-06(预期如何)

If the mysql-connector-java returns to 6.0.6 and thus mysql.jdbcUrl = jdbc:mysql://localhost:3306/web_v01?useSSL=false (no serverTimezone=UTC) rs.getDate("fecha") returns 1981-07-06 (how is expected)

因此如何使用 8.0.11 解决此问题?

Thus how fix this working with 8.0.11?.

serverTimezone 从一开始就没有声明时,我希望有相同的行为,当然要避免异常.

I want have the same behaviour when serverTimezone never was declared from the beginning, of course avoiding the exception.

因此,如果考虑到声明 serverTimezone 的值无关紧要,那么解决方案会更好.

Therefore the solution would be better if is take it in consideration that does not matter what value for serverTimezone was declared.

推荐答案

尝试使用

jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=CST

这篇关于mysql-connector-java 升级到 8.0.11 会更改从数据库中检索到的所有日期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆