pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-jdbc@postgresql.org
Subject: Re: Timestamp vs. Java Date/Timestamp
Date: Wed, 13 Feb 2013 17:13:06 +0100
Message-ID: <kfge0s$l8m$1@ger.gmane.org> (raw)
In-Reply-To: <1360733845.24220.50.camel@localhost>
References: <1360043227.14635.9.camel@localhost>
	<CADK3HHJDvnHzcbEu2CMJ7g_riuMTi6D-=1mdvc+T-9DYEidvJA@mail.gmail.com>
	<1360733845.24220.50.camel@localhost>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

Andreas Reichel, 13.02.2013 06:37:
> 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.

But due to the removing of the time part this will *not* work.

> 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.

Yes, that's per documentation.

http://docs.oracle.com/javase/6/docs/api/java/sql/Date.html

"To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date
instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero [...]"

Note the part about "setting ... to zero"

So as soon as you create a java.sql.Date you lose the time information.
  
If you want to be JDBC compliant there are only two simple things to remember:

* use java.sql.Date together with setDate()/getDate() for date columns
* use java.sql.Timestamp together with setTimestamp()/getTimestamp() for timestamp columns

This works across all DBMS that I have worked with
(Oracle is a bit special but in general you should simply treat their DATE as timestamp)

The only problem are columns with timezones as none of the Java classes can deal with that.

Thomas




-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



view thread (13+ messages)  latest in thread

Message-ID: <kfge0s$l8m$1@ger.gmane.org>
Permalink:  ../kfge0s$l8m$1@ger.gmane.org/
Also on:    postgresql.org/message-id/kfge0s$l8m$1@ger.gmane.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: spam_eater@gmx.net
  Subject: Re: Timestamp vs. Java Date/Timestamp
  In-Reply-To: <kfge0s$l8m$1@ger.gmane.org>
  References: <1360043227.14635.9.camel@localhost> <CADK3HHJDvnHzcbEu2CMJ7g_riuMTi6D-=1mdvc+T-9DYEidvJA@mail.gmail.com> <1360733845.24220.50.camel@localhost> <kfge0s$l8m$1@ger.gmane.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox