Re: Timestamp vs. Java Date/Timestamp

From: dmp <danap(at)ttc-cmc(dot)net>
To: Dave Cramer <pg(at)fastcrypt(dot)com>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Timestamp vs. Java Date/Timestamp
Date: 2013-02-13 17:26:25
Message-ID: 511BCCC1.7050404@ttc-cmc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Heikki Linnakangas 2013-02-13 17:55:28 Re: PostgreSQL XAResource & GlassFish 3.1.2.2
Previous Message Thomas Kellerer 2013-02-13 16:13:06 Re: Timestamp vs. Java Date/Timestamp