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?

2
  • stackoverflow.com/questions/2305973/… see the differenced between java and sql's date objects Commented Jul 17, 2012 at 10:26
  • Thank you so much and sorry for duplicate Commented Jul 17, 2012 at 10:58

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.