Serious JDBC problem

Поиск
Список
Период
Сортировка
От Bayless Kirtley
Тема Serious JDBC problem
Дата
Msg-id E4CECA494A6241CE85C6C2E5FA3DA9C4@dell2400
обсуждение исходный текст
Ответы Re: Serious JDBC problem  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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


В списке pgsql-general по дате отправления:

Предыдущее
От: Mike Christensen
Дата:
Сообщение: Re: Replication
Следующее
От: "Joshua D. Drake"
Дата:
Сообщение: Re: Replication