Wednesday, November 6

Date/Time between java and db (mysql)

Thanks for almighty StackOverflow, the answer is here :

The most error-prone part is:
In contrary to java.util.Date(which contains information about both the date and time parts), the java.sql.Date contains only information about the date part (year, month, day).
So to retrieve both date and time of the record, the obvious way 
java.util.Date record_date = rs.getDate("record_date");
doesn't work. It has to be:
java.util.Timestamp ts = rs.getTimestamp("record_date");
java.util.Date record_date = rs;


Links to this post:

Create a Link

<< Home