Bug #91379 Off by one error on dates
Submitted: 22 Jun 2018 16:48 Modified: 25 Jun 2018 8:21
Reporter: Keith Johnston Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:8.0.11 OS:CentOS
Assigned to: CPU Architecture:Any

[22 Jun 2018 16:48] Keith Johnston
Description:
When updating dates using prepared statements, dates are being saved off by one in the database.

Server version: 5.6.39
connector Java: 8.0.11
jdk1.8.0_172

How to repeat:
Sample code:

// data populated in items as:
java.sql.Date date = java.sql.Date.valueOf("2018-08-13");

Connection con = dataSrc.getConnection();
PreparedStatement stmt = con.prepareStatement("update items set eventDate=? where id=?");
while (items.hasNext()) {
    Item next = items.getNext();
    stmt.setDate(1, next.getDate());
    stmt.setInt(2, next.getId()));
    stmt.addBatch();
}
stmt.executeBatch();

I've debugged the Java code and put breakpoints where setDate is being called and confirmed the correct date is being passed in, but it ends up one day less in the database.
[22 Jun 2018 17:13] Keith Johnston
Downgrading to connector J 5.1.46 and com.mysql.jdbc.Driver instead of com.mysql.cj.jdbc.Driver fixed the problem without any changes to application code.
[25 Jun 2018 7:58] Chiranjeevi Battula
Hello Keith Johnston,

Thank you for your feedback.
I'm glad that you found a solution for your problem and let us know if you are still having the issue with complete repeatable steps.

Thank you for your interest in MySQL.

Thanks,
Chiranjeevi.
[25 Jun 2018 8:21] Keith Johnston
My report details how to reproduce the problem in the latest version of the driver. 

Odd that you think downgrading to an ancient version is an acceptable solution.