X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id AC410D93EC for ; Mon, 7 Nov 2005 01:52:03 -0400 (AST) 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 98724-03 for ; Mon, 7 Nov 2005 05:52:01 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [131.203.101.226]) by svr1.postgresql.org (Postfix) with ESMTP id 9DCEBD9364 for ; Mon, 7 Nov 2005 01:52:00 -0400 (AST) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=[192.168.0.20]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1EYzvB-0002Y1-6b; Mon, 07 Nov 2005 18:51:57 +1300 Message-ID: <436EEB7C.7090607@opencloud.com> Date: Mon, 07 Nov 2005 18:51:56 +1300 From: Oliver Jowett User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051009) X-Accept-Language: en-us, en MIME-Version: 1.0 To: =?ISO-8859-1?Q?Eli=E9zer_Madeira_de_Campos?= Cc: pgsql-jdbc@postgresql.org Subject: Re: 7.3 -> 8.0.4 migration timestamp problem References: <54CC7CADE26E884EB2BCEC863F5C1F70F9D263@moscou.diuno.net> In-Reply-To: <54CC7CADE26E884EB2BCEC863F5C1F70F9D263@moscou.diuno.net> Content-Type: multipart/mixed; boundary="------------070008020702070100020000" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.008 required=5 tests=[AWL=0.008] X-Spam-Score: 0.008 X-Spam-Level: X-Archive-Number: 200511/37 X-Sequence-Number: 14135 This is a multi-part message in MIME format. --------------070008020702070100020000 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Eliézer Madeira de Campos wrote: > 1) Timestamp before 1914. > When I execute the query by java statement no problem occurs, but when I execute the query > by java preparedstatement this is what happens: > > PreparedStatement pst = con.prepareStatement("insert into teste values (?, ?, ?)"); > pst.setObject(1, new Integer(1)); > pst.setObject(2, "TESTE"); > Calendar c = new GregorianCalendar(1913, 0, 1, 0, 0, 0); > Timestamp t = new Timestamp(c.getTimeInMillis()); > pst.setTimestamp(3, t); > pst.executeUpdate(); > > The date stored in database is actually 1912-12-31 23:53:12.0 (however it should have stored 1913-01-01. > > I have already debugged the Postgres-8.0 (build 313) driver and it seems to send the correct date to database. I could not reproduce this problem using the attached testcase against 8.0.3 and the build 313 driver. I get the expected output: > $ java -classpath .:postgresql-8.0-313.jdbc3.jar TestTimestamp6 'jdbc:postgresql:test?user=oliver' > 1 => 1913-01-01 00:00:00.0 (literal '1913-01-01 00:00:00') What are you doing differently? Perhaps the JVM and server timezone settings are important, what are you using? -O --------------070008020702070100020000 Content-Type: text/plain; name="TestTimestamp6.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="TestTimestamp6.java" import java.sql.*; import java.util.*; import java.text.*; public class TestTimestamp6 { public static void main(String[] args) throws Exception { Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection(args[0]); Statement stmt = conn.createStatement(); try { stmt.executeUpdate("DROP TABLE testtimestamp6"); } catch (SQLException e) {} stmt.executeUpdate("CREATE TABLE testtimestamp6(index int4, datetime timestamp without time zone)"); PreparedStatement pst = conn.prepareStatement("insert into testtimestamp6 values (?, ?)"); pst.setObject(1, new Integer(1)); Calendar c = new GregorianCalendar(1913, 0, 1, 0, 0, 0); Timestamp t = new Timestamp(c.getTimeInMillis()); pst.setTimestamp(2, t); pst.executeUpdate(); ResultSet rs = stmt.executeQuery("select * from testtimestamp6"); while (rs.next()) { int index = rs.getInt(1); Timestamp ts = rs.getTimestamp(2); String ts_text = rs.getString(2); System.out.println(index + " => " + ts + " (literal '" + ts_text + "')"); } } } --------------070008020702070100020000--