Serious JDBC problem

From: "Bayless Kirtley" <bkirt(at)cox(dot)net>
To: "List, Postgres" <pgsql-general(at)postgresql(dot)org>
Subject: Serious JDBC problem
Date: 2009-06-24 19:21:37
Message-ID: E4CECA494A6241CE85C6C2E5FA3DA9C4@dell2400
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

For some reason, the PostgreSQL JDBC driver fails to properly recognize
daylight saving time. When retrieving the current time as a java.sql.Time,
if returns an hour behind when DST is in effect.

Here is a tested sample Java code that demonstrates the error..

private void getTime(Connection conn) {
try {
Statement stmt = conn.createStatement();
ResultSet result = stmt.executeQuery("Select CURRENT_TIME");
result.next();
String timeStr = result.getString(1);
System.out.println("String: " + timeStr);
java.sql.Time time = result.getTime(1);
System.out.println("Time: " + time);
java.sql.Time sysTime = new java.sql.Time(new
java.util.Date().getTime());
System.out.println("Run at:" + sysTime);
}
catch (SQLException e) {
System.out.println(e.getMessage());
}
}

The output from running this code is:

String: 09:23:37.302-05
Time: 08:23:37
Run at: 09:23:37

As you can see it was run at 09:23:37 local daylight saving time today.
Retrieving PostgreSQL time as a String also gives that same value.
Retrieving it as a Time gives a value of one hour earlier. Presumably
it is not recognizing daylight saving time. Since it produces two quite
different values for the same query, this seems to be a serious flaw
in the JDBC driver. The driver in use is "org.postgresql.Driver" with
PostgreSQL 8.3.1-1, installed about a year ago. I have tried this with
postgresql-8.3-603.jdbc3.jar and postgresql-8.3-603.jdbc4.jar with
the same result. I am using Java 1.6 but it did the same thing last year
with 1.5.

Bayless

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2009-06-24 19:25:43 Re: Replication
Previous Message Mike Christensen 2009-06-24 19:13:22 Re: Replication