X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3CDA25E46C3 for ; Wed, 18 Aug 2004 15:17:27 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 90201-08 for ; Wed, 18 Aug 2004 18:17:32 +0000 (GMT) Received: from smtp.ops.co.at (ops004.ops.co.at [194.152.182.4]) by svr1.postgresql.org (Postfix) with ESMTP id 763895E37CB for ; Wed, 18 Aug 2004 15:17:22 -0300 (ADT) Received: by smtp.ops.co.at (Postfix, from userid 65534) id 1AEEC23C0A4; Wed, 18 Aug 2004 20:17:28 +0200 (CEST) Received: from [10.0.0.12] (mgate.int.ops.co.at [172.27.0.11]) by smtp.ops.co.at (Postfix) with ESMTP id 53B5623C0A3 for ; Wed, 18 Aug 2004 20:17:25 +0200 (CEST) Message-ID: <41239D59.1020806@apache.org> Date: Wed, 18 Aug 2004 20:18:01 +0200 From: Mario Ivankovits User-Agent: Thunderbird 0.7.3 (Windows/20040803) X-Accept-Language: de-DE, de, en-us, en MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: pgdev.305.jdbc3, postgresql 8.0 and timestamps Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/105 X-Sequence-Number: 10827 Hello ! I have a problem with the pgdev.305.jdbc3 driver and timestamps. I created a simple table where the primary key is a timestamp field. Then i inserted a row with the timestamp: 2004-08-17 21:00:00 If i select the record using this date 2004-08-17 21:00:00 it will return the correct row, but a getTimestamp on this row will report 2004-08-17 19:00:00 instead of 2004-08-17 21:00:00. The timestamp in the database shows 2004-08-17 19:00:00. So there is a timezone discrepance between the data sent to the database and the data read back from it. Here you will find a short test for this. The Java snipplet should return date: 2004-08-17 21:00:00.0/1092769200000 update: 1 DateA: 2004-08-17 21:00:00.0/1092769200000 DateB: 2004-08-17 21:00:00.0/1092769200000 but it returns date: 2004-08-17 21:00:00.0/1092769200000 update: 1 DateA: 2004-08-17 19:00:00.0/1092762000000 I can wokaround it by using "timestamptz" instead of "timestamp" or using the "pg74.1jdbc3.jar" driver. I found this problem with hibernate (www.hibernate.org) when it tries to delete an object but the database cant find it. I just tried to break down the sequence to plain jdbc calls - and here it is: CREATE TABLE tt ( ttt timestamp NOT NULL, CONSTRAINT ttpkey PRIMARY KEY (ttt) ) WITHOUT OIDS; public static void main(String[] args) throws Exception { Class.forName("org.postgresql.Driver"); Timestamp dd = new java.sql.Timestamp(new Date(2004-1900, 8-1, 17, 21, 0, 0).getTime()); System.err.println("date: " + dd + "/" + dd.getTime()); Connection con = DriverManager.getConnection("jdbc:postgresql:db", "usr", "pass"); PreparedStatement stm = con.prepareStatement("insert into tt values(?)"); stm.setTimestamp(1, dd); System.err.println("update: " + stm.executeUpdate()); stm = con.prepareStatement("select * from tt where ttt = ?"); stm.setTimestamp(1, dd); ResultSet rs = stm.executeQuery(); while (rs.next()) { dd = rs.getTimestamp("ttt"); System.err.println("DateA: " + dd + "/" + dd.getTime()); } rs.close(); stm = con.prepareStatement("select * from tt where ttt = ?"); stm.setTimestamp(1, dd); rs = stm.executeQuery(); while (rs.next()) { Date d = rs.getTimestamp("ttt"); System.err.println("DateB: " + d + "/" + d.getTime()); } rs.close(); } Ciao, Mario