Possible Duplicate:
MySql datetime not returning time
If I do this from consele mysql:
SELECT CREATION from MYDATABASE WHERE NAME='MyData';
I get 2012-07-12 13:42:55
but if do this from Java:
String sql = "SELECT CREATION from MYDATABASE WHERE NAME=?";
PreparedStatement ps = null;
String creationQuery;
ResultSet rs = null;
try
{
ps = conn.prepareStatement(sql);
ps.setString(1, "MyData");
rs = ps.executeQuery();
creationQuery = rs.next() ? rs.getString(1) : null;
}
I get 2012-07-12 13:42:55.0
Why?
It has to do with the fact that what you receive from your Java query is a
java.sql.Timestamp, which is a wrapper to a regularutil.Datethat also holds nanoseconds.If you look at the
toString()method of that class you see that it is overridden to use the formatwhere
represent nanoseconds.
Both results represent the same time though, it is just a difference in representation.