MySQL: Data truncation: Incorrect datetime value: '2006-10-01 02:22:44'

前端 未结 5 2225
遥遥无期
遥遥无期 2021-02-19 09:22

I\'m getting the following exception updating a row using MySQL via JDBC:

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: \

5条回答
  •  遥遥无期
    2021-02-19 09:45

    My problem was caused by DST, too. I've fixed it by changing column data type from timestamp to datetime. This answer describes the difference, in short:

    • timestamp stores time as Unix epoch time, so converts it to/from UTC according to server's time zone. Once you change server time zone, you have different interpretation for INSERT/UPDATE and different SELECT results. Some time points are invalid due to DST;
    • datetime stores time as is, regardless of server time zone. When passing UTC time, any time is valid (there are no DST "holes").

    Note: you may still have to deal with "missing" time. This approach just shifts responsibility from DB level to application level.

    See also: MySQL documentation for TIMESTAMP vs DATETIME

提交回复
热议问题