Two Laptop Bag*
The moose likes JDBC and the fly likes Informix and ResultSet.getTimestamp() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Informix and ResultSet.getTimestamp()" Watch "Informix and ResultSet.getTimestamp()" New topic
Author

Informix and ResultSet.getTimestamp()

Chip Gobs
Greenhorn

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).
Example:
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");
utcSdf.setTimeZone(utcTimeZone);

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

//-----------------------------------------------------------------------
Thanks,
Chip
 
 
subject: Informix and ResultSet.getTimestamp()
 
Similar Threads
Convert Local time to UTC and vice versa
Calendar() / Date() bug ???
Converting to UTC time zone
java.sql.ResultSet getTimestamp Locale issue
getTimeStamp() returns a UTC time