Re: Timestamp vs. Java Date/Timestamp

From: Andreas Reichel <andreas(at)manticore-projects(dot)com>
To: Dave Cramer <pg(at)fastcrypt(dot)com>
Cc: List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Timestamp vs. Java Date/Timestamp
Date: 2013-02-13 05:37:25
Message-ID: 1360733845.24220.50.camel@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Dave,

please find a test attached. I guess, I can shed some light on it in the
meantime.

To me it seems, that setDate()/getDate() indeed ignores any time values
(hh:mm:ss.s) but parses the day-part only (yyyy-mm-dd).
At the same time, setTimestamp()/getTimestamp() behaves correctly.

(Note: in Postgres Date is Date only without Time, while Timestamp obeys
the Time, I was not completely aware of this. I thought the only
difference between Date and Timestamp is Milliseconds vs. Nanoseconds.)

On the same time java.sql.Date and java.util.Date support time
information and in fact you can handover a java.sql.Date parameter to a
Timestamp field.

This is the part when I get confused: the timestamp field holds time
information, the java.sql.Date parameter holds time information -- still
it is cut off in the middle.

Now I would like to suggest a couple of small changes:
a) allow java.util.Date in setObject() and convert it into
java.sql.Timestamp automatically
b) keep the time info whenever setting/returning java.sql.Date to/from a
Timestamp field

However, for the moment I am fine as I understood now the need for using
java.sql.Timestamp when working with time.

Thank you a lot and best regards
Andreas

PS:

Attachment Content-Type Size
Test.java text/x-java 2.8 KB

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2013-02-13 11:29:05 Re: Timestamp vs. Java Date/Timestamp
Previous Message Craig Ringer 2013-02-13 03:12:09 Re: [HACKERS] JPA + enum == Exception