开发者

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

开发者 https://www.devze.com 2023-04-07 15:06 出处:网络
I\'m getting the following exception updating a row using MySQL via JDBC: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: \'2006-10-01 02:22:44\'

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

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '2006-10-01 02:22:44'

The column is defined as:

'created_on_service timestamp NULL DEFAULT NULL'

There are no indexes or foreign keys on that column.

Obviously it's not a problem with data type. I have values in that table from both before and after that datetime. I also have valu开发者_开发技巧es with times both before and after 2:22 AM.


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.


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.


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.


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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号