aspose file tools
The moose likes JDBC and Relational Databases and the fly likes Informix and ResultSet.getTimestamp() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Informix and ResultSet.getTimestamp()" Watch "Informix and ResultSet.getTimestamp()" New topic

Informix and ResultSet.getTimestamp()

Chip Gobs

Joined: Feb 15, 2001
Posts: 13
I can't get the ResultSet.getTimestamp(int, Calendar) method to do what I
expect it to do. I expect the time in the database (which is stored
without any timezone info, but is intended to be in UTC) to be reflected
in the following code fragment. Unfortunately, it seems as if adding the
Calendar argument is doing the same thing as the
ResultSet.getTimestamp(int) method. It is reading the time from the
database and making it my local time instead of UTC. So it ends up 4 or 5
hours off (depending on time of year).
The time in the database is 2003-08-04 03:00:00 UTC, but it
comes back as 2003-08-04 03:00:00 EDT.

I am using the Informix jdbc driver: com.informix.jdbc.IfxDriver

Am I missing something, or is this a known problem?
I have a workaround, which is to get the Timestamp as a String and parse it
using SimpleDateFormat. I haven't checked the Daylight Saving Time extremes, yet though. I have other workarounds, but I don't want to have to
use them.
See the following code fragment to see what I am talking about.

TimeZone utcTimeZone = TimeZone.getTimeZone("UTC");
Calendar utcCalendar = new GregorianCalendar(utcTimeZone);
// note: column 6 is of type "datetime year to second"
// new way
Timestamp ts1 = rs.getTimestamp(6, utcCalendar);
// old way
//Timestamp ts1 = rs.getTimestamp(6);
SimpleDateFormat utcSdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

System.out.println("time = " + utcSdf.format(ts1.getTime());

I agree. Here's the link:
subject: Informix and ResultSet.getTimestamp()