0

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?

Community
  • 1
  • 1
Jjreina
  • 2,633
  • 6
  • 33
  • 54

1 Answers1

4

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 regular util.Date that also holds nanoseconds.
If you look at the toString() method of that class you see that it is overridden to use the format

yyyy-mm-dd hh:mm:ss.fffffffff

where

fffffffff

represent nanoseconds.

Both results represent the same time though, it is just a difference in representation.

Keppil
  • 45,603
  • 8
  • 97
  • 119