0

I have a Date type column in one of our tables and when I query the database I get the date from the resultset like:

 final String createdDate = resultSet.getString("received_date");  

If I run this on OC4J container on Java 5 I get

2014-12-26 05:57:31.0

while on Tomcat with Java 8 I get

2014-12-26 05:57:31

The JDBC driver are of different versions - do you think I should blame the driver for this? Is it a good direction regarding the investigation? Or is it more about Java version difference?

Thanks

HamoriZ
  • 2,370
  • 18
  • 38
  • 3
    Why are you using `getString` at all if it's a `Date` column? Why not fetch it *as a date*? – Jon Skeet Jan 23 '15 at 10:44
  • No, you should blame it on the poor decision for storing a Date type in a String column. Formatting is a rendering issue. – duffymo Jan 23 '15 at 10:44
  • It is a legacy code, do not ask why it was implemented so... Actually this is not the strangest thing in that codebase... – HamoriZ Jan 23 '15 at 10:51
  • 2
    Legacy code can still be corrected. At the very least you can specify the date format model explicitly with a `to_char()` call in your query, which you haven't shown; but retrieving it as a date would be better, – Alex Poole Jan 23 '15 at 10:57
  • You are absolutely right, but I would like to understand why it behaves differently. How to fix it is a different topic – HamoriZ Jan 23 '15 at 11:05
  • 1
    @HamoriZ - [looks like it is driver specific](http://stackoverflow.com/a/21174524/266304), but 'blame' is perhaps not the right term *8-) – Alex Poole Jan 23 '15 at 11:31

0 Answers0