I\'m looking at some code that basically does the following:
ResultSet rs = ps.executeQuery();
String myDateStr = rs.getString(\"MY_DATE\"); //field is of ty
For the Oracle JDBC driver I am using, the format is hard-coded in the driver library, so should only differ across systems if different driver versions are in use.
See my attempt to get an answer to the same question here: Where is the date format specified when reading a date as a string from JDBC ResultSet.
(Apologies for asking a separate question, but as your question had been answered multiple times with the ever-helpful "just don't do that" response, I tried again...).
try this:
ResultSet rs = ps.executeQuery();
Date myDate = rs.getDate("MY_DATE");
or this :
ResultSet rs = ps.executeQuery();
String myDateStr = rs.getString("MY_DATE");
Date myDate = valueOf(myDateStr);
More about date: http://docs.oracle.com/javase/7/docs/api/java/sql/Date.html
More about ResultSet : http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html
Instead of using
String myDateStr = rs.getString("MY_DATE")
you should use
Timestamp timestamp = rs.getTimestamp("MY_DATE");
JDBC / Database will handle the date transformation for you.
If the field is of type Date
, then read it as a java.sql.Date
and do whatever conversion you need after that. Otherwise you're at the mercy of the database implementation.