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

前端 未结 5 2255
遥遥无期
遥遥无期 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

    0 讨论(0)
  • 2021-02-19 09:50

    Solved it.

    Turns out that the 1st of October 2006 in South Australia was the start of daylight savings. Clocks get set forward one hour at 2.00am, so there was no 2:22am on that date: it went straight from 2:00am to 3:01am.

    I'll change the db timezone to UTC, which should solve this issue.

    0 讨论(0)
  • 2021-02-19 09:51

    You did not show exact update SQL. But may be you forget the date part

    The correct format is yyyy-mm-dd hh:mm:ss format

    Date value should be in following format 2011-11-01 12:32:01

    0 讨论(0)
  • 2021-02-19 09:57

    We upgraded MySQL server but didnt upgrade the mysql connector jar. We encountered this issue. Later I figured out it was due to the old jar. I upgraded it and this issue went away.

    0 讨论(0)
  • 2021-02-19 10:03

    I fixed the same problem (com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '' for column 'perev_start_time' at row 1) by upgrading my MySQL connector JAR, and copying the mysql.jar to the Tomcat lib directory.

    The version of MySQL Server is 5.6 and the MySQL connector is mysql-connector-java-5.1.30-bin.jar.

    0 讨论(0)
提交回复
热议问题