For a Spring project, the mysql-connector-java
has been migrated from 6.0.6
to 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.
After to do a research
the solution is change the URL
(I don't want return to a previous release)
- from:
mysql.jdbcUrl = jdbc:mysql://localhost:3306/web_v01?useSSL=false
- to:
mysql.jdbcUrl = jdbc:mysql://localhost:3306/web_v01?useSSL=false&serverTimezone=UTC
Observe the addition of &serverTimezone=UTC
In my DB I have the following:
mysql> select * from persona;
+-----+--------------+-------------+------------+
| id | nombre | apellido | fecha |
+-----+--------------+-------------+------------+
...
| 088 | Something | Something | 1981-07-06 |
...
+-----+--------------+-------------+------------+
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)
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)
Thus how fix this working with 8.0.11
?.
I want have the same behaviour when serverTimezone
never was declared from the beginning, of course avoiding the exception.
Therefore the solution would be better if is take it in consideration that does not matter what value for serverTimezone
was declared.