Wednesday, July 1, 2009

JDBC to MySQL Datetime (Time truncated)

Be careful when accessing Datetime fields in a MySQL database through JDBC. You might think that the java.sql.Date would work, but that actually truncates the Date back to midnight. In order to access the actual time, use getTimestamp() instead. Here is the code:

Result rs = ...
while ( {
return rs.getTimestamp(1).getTime();


peterjohn said...

Pretty good post. I just came across your site and wanted to say that I’ve really enjoyed reading your posts. In any case I’ll be subscribing to your feed and I hope you will keep a good work!Cheer!

sap online training
software online training
sap sd online training
hadoop online training

peterjohn said...

This is one awesome blog article. Much thanks again.
I really enjoy the blog.Much thanks again. Really Great.

oracle online training
sap fico online training
dotnet online training