JDBC Driver and timezones

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: JDBC Driver and timezones
Date: 2010-05-18 09:29:37
Message-ID: hstmm1$96v$1@dough.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi,

I have a little problem regarding timezones in the JDBC driver.

I have a locally installed Postgres server (PG 8.4.3 on Windows XP), so there is no difference between the timezone of the server and the client application.

When I run the following in psql:

select current_time, localtime;

I get the following output:

timetz | time
-----------------+--------------
11:15:30.464+02 | 11:15:30.464
(1 row)

which is fine.

Now when I run the same statement through JDBC :

Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select current_time, localtime");
if (rs.next())
{
System.out.println("current_time: " + rs.getTime(1).toString());
System.out.println("localtime: " + rs.getTime(2).toString());
}

I get the following output:

current_time: 10:18:49
localtime: 11:18:49

My expectation would have been to get the same display, but the current_time is one our off, which seems to be a problem with the daylight savings time.I

The timezone for my computer is setup correctly (the clock is showing the correct time, and apparently psql has the correct time as well)

The display from Java only works if I explicitely set the timezone when starting the JVM using -Duser.timezone=GMT+2

Is this a Java/JDK problem, a Windows problem or a driver problem?
I'm using JDK 1.6.0_18

Regards
Thomas

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Rod 2010-05-18 10:41:05 After server restart I get - An I/O error occured while sending to the backend.
Previous Message Craig Ringer 2010-05-18 02:28:46 Re: Connection fails when the user name contains chinese characters