Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Informix and ResultSet.getTimestamp()  RSS feed

Chip Gobs
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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());

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!