Re: Confusion about JDBC + TIME WITHOUT TIME ZONE - Mailing list pgsql-jdbc

From Philippe Marschall
Subject Re: Confusion about JDBC + TIME WITHOUT TIME ZONE
Date
Msg-id 56A606AC.6020707@netcetera.ch
Whole thread Raw
In response to Confusion about JDBC + TIME WITHOUT TIME ZONE  (Bill Moran <wmoran@potentialtech.com>)
List pgsql-jdbc
On 25.01.16 01:00, Bill Moran wrote:
>
> I have a table that has a TIME WITHOUT TIME ZONE column.
>
> When I try to insert via JDBC, the time is always adjusted for the
> JVM's time zone. This behavior seems wrong to me. For example:
>
> // Java code:
> preparedStatement.setTime(1, Time.valueOf("00:00:10"));
>
> Then, watching the PostgreSQL logs, I see that the value supplied
> for parameter #1 is '05:00:10'.

I am more leaning towards a bug. Can you try the following on a
TIMESTAMP WITHOUT TIME ZONE column?

preparedStatement.setTimestamp(1, java.sql.Timestamp.valueOf("2016-01-25
00:00:10"));

If in that case the time (of the timestamp) stored is actually
'00:00:10' then I would argue for a bug. The reasoning being:

The java.sql date and time classes (Date, Time and Timestamp) are to be
interpreted in the JVM default time zone in the case of WITHOUT TIME
ZONE database types.

For example:
  - For a TIMESTAMP WITHOUT TIME ZONE what in SQL is '2016-01-25
00:00:10' will be in Java java.sql.Timestamp 2016-01-25 00:00:10 in the
JVM default time zone
  - For a DATE WITHOUT TIME ZONE what in SQL is '2016-01-25' will be
java.sql.Date 2016-01-25 00:00:00 in the JVM default time zone (the time
is added because java.util.Date instance implicitly always have a time)

If the agree on this then it would make sense that
  - For a TIME WITHOUT TIME ZONE what in SQL is '00:00:10' will be
java.sql.Time 1970-01-01 00:00:10 in the JVM default time zone (the date
is added because java.util.Date instance implicitly always have a date
and in this case 1970-01-01 is specified)


Cheers
Philippe



pgsql-jdbc by date:

Previous
From: Vladimir Sitnikov
Date:
Subject: Re: Merge pgjdbc-parent-poms project into pgjdbc please
Next
From: Pavel Raiskup
Date:
Subject: Re: Merge pgjdbc-parent-poms project into pgjdbc please