pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Eliézer Madeira de Campos <eliezer@diuno.com.br>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: 7.3 -> 8.0.4 migration timestamp problem
Date: Mon, 07 Nov 2005 18:51:56 +1300
Message-ID: <436EEB7C.7090607@opencloud.com> (raw)
In-Reply-To: <54CC7CADE26E884EB2BCEC863F5C1F70F9D263@moscou.diuno.net>
References: <54CC7CADE26E884EB2BCEC863F5C1F70F9D263@moscou.diuno.net>

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

Attachments:

TestTimestamp6.java (text/plain, 1.2K) download 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 + "')"); } } }

view thread (5+ messages)

Message-ID: <436EEB7C.7090607@opencloud.com>
Permalink:  ../436EEB7C.7090607@opencloud.com/
Also on:    postgresql.org/message-id/436EEB7C.7090607@opencloud.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: oliver@opencloud.com, eliezer@diuno.com.br
  Subject: Re: 7.3 -> 8.0.4 migration timestamp problem
  In-Reply-To: <436EEB7C.7090607@opencloud.com>
  References: <54CC7CADE26E884EB2BCEC863F5C1F70F9D263@moscou.diuno.net> <436EEB7C.7090607@opencloud.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox