• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Informix and ResultSet.getTimestamp()

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic