Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getDate() returning odd value

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a DB2 database, and I have a row that has a value of '1900-01-01' of the Date type in a column. In my java application, when I do a getDate() (just printing to std out) on this column, it returns a value of 2011-06-30. What's up?
Thanks for any help!
[ February 11, 2003: Message edited by: Jennifer Sohl ]
[ February 12, 2003: Message edited by: Jennifer Sohl ]
 
Jon Dornback
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jennifer Sohl:
I am using a DB2 database, and I have a row that has a value of '1900-01-01' of the Date type in a column. In my java application, when I do a getDate() (just printing to std out) on this column, it returns a value of 2011-06-30. What's up?
Thanks for any help!
[ February 11, 2003: Message edited by: Jennifer Sohl ]
[ February 12, 2003: Message edited by: Jennifer Sohl ]

the java Date class is very finicky - I have gotten different dates when converting from a String to a Date to a Calendar back to a String. So, you might want to look in to the ResultSet.getDate(String, Calendar). Or, if that doesn't work, look at the java.text.SimpleDateFormat class. With that, you can create rules on how to interpret a String as a Date, and then use ResultSet.getString() instead of .getDate() and parse the results. good luck.
Jon
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. However, I just found out what my problem was. It is in my connection.
Here is what I had to do:

Apparently DB2 wants you to specify the date format in the connection. After I added the "date format=iso" everything worked great!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic