When I try to use a java.sql.Timestamp value to insert into a DATETIME column in MySQL 5.6, I always get this error:
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '' for column 'invoice_date' at row 1
The original developer of this project had custom JARs that created the Prepared statements, such that java.util.Date is converted into Timestamp to be inserted into DATETIME and vice versa, as well as handled database connections. Note that this is my assumption since there is no documentation about it. Trying to use a timestamp to insert into DATETIME myself via PreparedStatement had the same results, using something like:
ps.setTimestamp(3, new Timestamp(date.getTime()));
I had to create my own connection so that I can use java.sql.Date to solve this problem. However it zeroes the time value as a result. I used
ps.setDate(3, new java.sql.Date(date.getTime()));
And I get something like
2013-06-27 00:00:00
in the table, since as we know java.sql.Date doesn't store the time.
Surprisingly, on a server that uses MySQL 5.0, this works normally. I'm assuming the millisecond value in Timestamp is causing the problem casting into DATETIME? Since the original works in older versions. Is there any way to resolve this without having to reinstall everything with 5.0?