|
|||||||||||
|
[JDBC] Timestamp without timezone issue
From: Chip Gobs <chip.gobs(at)noaa.gov>
Date: Tue Dec 04 2007 - 15:28:20 EST We recently changed from using PostgreSQL 7.4.8 to 8.2.5 and switched the JDBC driver to the 8.2.506 version from the 74.215 version. We are and have been using build 1.5.0_04-b05 of the J2SE since before our Postgres version change.
After switching, we started receiving large numbers of errors in the
postgres error log file. These are unique constraint errors on UPDATEs,
when we are not actually trying to change any of the key columns. The
errors are reported as follows (irrelevant non-key columns have been
removed for clarity):
The key columns on this table are lid, pe, dur, ts, extremum and obstime.
Notice the (-06 US Central time) time zone information in the log
message.
A workaround is to use: SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); formatter.setTimeZone(TimeZone.getTimeZone("UTC")); dateTimeString = formatter.format(new java.util.Date(timeInMillis)); Timestamp timestamp = Timestamp.valueOf(dateTimeString); statement.setTimestamp(index, timestamp); The following did not work: TimeZone tz = TimeZone.getTimeZone("UTC"); Calendar cal = Calendar.getInstance(tz); Timestamp timestamp = new Timestamp(timeInMillis); statement.setTimestamp(index, timestamp , cal); Neither did: Timestamp timestamp = new Timestamp(timeInMillis); statement.setTimestamp(index, timestamp); Is this a known issue, a new one, or was I doing something wrong? Thanks, Chip Gobs ---------------------------(end of broadcast)---------------------------TIP 7: You can help support the PostgreSQL project by donating at
http://www.postgresql.org/about/donate
Received on Tue Dec 4 15:29:28 2007This archive was generated by hypermail 2.1.8 : Wed Jun 18 2008 - 23:40:48 EDT |
||||||||||
|
|||||||||||