Re: Timestamp vs. Java Date/Timestamp - Mailing list pgsql-jdbc

From dmp
Subject Re: Timestamp vs. Java Date/Timestamp
Date
Msg-id 511BCCC1.7050404@ttc-cmc.net
Whole thread Raw
In response to Re: Timestamp vs. Java Date/Timestamp  (Dave Cramer <pg@fastcrypt.com>)
List pgsql-jdbc
I agree that more things would break then fix. setDate() should
not be used to fill a PostgreSQL TIMESTAMP data type field.

It is fine to use in the application java.util.Date, but then just
convert it to the TIMESTAMP type for PostgreSQL in setTimeStamp() by
using java.util.Date.getTime(). Insure the format is correct though
with a SimpleDateFormat.

Timestamp With Time Zone, timestamptz, can also be handle exactly the
same way by just using the formatter to include a time zone.

SimpleDateFormat timeStampFormat;
java.sql.Timestamp dateTimeValue;
java.util.Date dateParse;

timeStampFormat = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss z");
dateParse = timeStampFormat.parse("2008-12-30 15:16:08 MST");
dateTimeValue = new java.sql.Timestamp(dateParse.getTime());
prepared_sqlStatement.setTimestamp(i++, dateTimeValue);

danap

Dave Cramer wrote:
> And I think that is the way it will remain. I'm afraid this would break
> way more than it would fix
>
>
>
> Dave Cramer



pgsql-jdbc by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: Timestamp vs. Java Date/Timestamp
Next
From: Heikki Linnakangas
Date:
Subject: Re: PostgreSQL XAResource & GlassFish 3.1.2.2