0

Here a piece of my code:

Map<String, Object> simpleJdbcCallResult =
                    new SimpleJdbcCall(jdbcTemplate)
                            .withProcedureName(procedureName)
                            .returningResultSet(parameterName, mapper)
                            .withCatalogName(catalogName)
                            .execute(parameters);

In my parameters, I have a LocalDateTime containing "2021-01-27T23:02:50", but when I look on the SQL query that is executed by Spring, I see the actual datetime passed to the database is "2021-01-27 22:02:50". See the one hour shift? Isn't LocalDateTime supposed to be without any notion of timezone? I can't see where the shift comes from.

Alexis Dufrenoy
  • 11,784
  • 12
  • 82
  • 124
  • of course localDatetime has no notion of time zone so my guess would be that your database might be set for a different timezone - could that be the reason? – J Asgarov Apr 27 '21 at 16:43
  • To a different timezone than what, if there is no timezone in the LocalDateTime? – Alexis Dufrenoy Apr 27 '21 at 17:12
  • well for example mysql has as timezone see here - https://stackoverflow.com/questions/930900/how-do-i-set-the-time-zone-of-mysql, maybe that is the thing that causes the hour shift - why not try changing the time setting of ur db and seeing if that has any effect? – J Asgarov Apr 27 '21 at 17:14
  • It's actually MySQL. I checked, and it is using the SYSTEM timezone. So I checked the CentOS timezone, which was set to CEST. I set it to Europe/Paris, which is my timezone. To no avail. Same problem. – Alexis Dufrenoy Apr 27 '21 at 17:17
  • could u try setting timezone explicitly for ur database: `jdbc:mysql://[db-host-address]/[db-name]?useLegacyDatetimeCode=false&serverTimezone=Europe/Paris` – J Asgarov Apr 27 '21 at 17:25
  • Ok, the JDBC connection settings actually indicated UTC. I changed for Europe/Paris, but still no improvement. – Alexis Dufrenoy Apr 27 '21 at 17:39
  • In the meantime, I tried to add a parameter to Spring Boot in order to start it on the right timezone: `-Duser.timezone=Europe/Paris`. Still no improvement... – Alexis Dufrenoy Apr 28 '21 at 08:13
  • The strange thing is, I tried to change the CentOS timezone, but the date command still indicates CEST as the timezone, and not Europe/Paris... – Alexis Dufrenoy Apr 28 '21 at 08:26
  • @JAsgarov Your last comment about the JDBC parameters actually solved the problem. I had timezone=UTC instead of timezone=Europe/Paris. If you are willing to write an answer, I'm ready to accept it. – Alexis Dufrenoy Apr 29 '21 at 13:22
  • Oh thanks, no need glad I could help:) – J Asgarov Apr 29 '21 at 15:01

0 Answers0