JDBC/MySQL: Save timestamp always using UTC

后端 未结 2 502
后悔当初
后悔当初 2021-01-03 06:31

I would like to save a timestamp to the database without being converted to the local timezone by the jdbc driver. Currently only MySQL and PostgreSQL are important for me b

2条回答
  •  佛祖请我去吃肉
    2021-01-03 06:59

    I found the solution. MySQL had a bug in their JDBC connector ignoring the provided Calendar object to setTimestamp/getTimestamp. They fixed the bug in version 5.1.5 of the connector but the old (incorrect) behaviour is still the default behaviour. To use the correct code you have to pass the parameter "useLegacyDatetimeCode=false" to the connector url.

    Further information: http://bugs.mysql.com/bug.php?id=15604

提交回复
热议问题