Thread: Serious JDBC problem

Serious JDBC problem

From
"Bayless Kirtley"
Date:
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


Re: Serious JDBC problem

From
Tom Lane
Date:
"Bayless Kirtley" <bkirt@cox.net> writes:
> 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.

You'd be best advised to ask about that on the pgsql-jdbc list...

            regards, tom lane