pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: Boris Kirzner <borisk@mainsoft.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Bug in storing Timestamp
Date: Thu, 14 Apr 2005 04:17:42 -0500 (EST)
Message-ID: <Pine.BSO.4.56.0504140407320.17685@leary.csoft.net> (raw)
In-Reply-To: <425A701C.6070608@mainsoft.com>
References: <425A701C.6070608@mainsoft.com>



On Mon, 11 Apr 2005, Boris Kirzner wrote:

> Short description :
> Storing java.sql.Timestamp with specified milliseconds value results to 
> wrong value stored in db.
> 
> PostgreSQL version : 8.0.1
> Driver version : 8.0 build 310
> 
> Detailed description :
> In order to reproduce the bug run the following code.
> Create the table in the db.
> The code creates a timestamp of "0001-01-01 02:02:02.0" and stores it 
> into the db.
> The actual value stored is "02:22:42".

I am not able to reproduce this problem.  The attached test case shows a
problem with storing java.sql.Time into a timetz type because the correct
offset is not saved, but that's not what you've described.  Perhaps it is
something specific to your timezone?

Kris Jurka

Attachments:

TimeTest.java (text/plain, 1.5K) download import java.sql.*; public class TimeTest { public static void main(String args[]) throws Exception { Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql://192.168.3.150:5432/jurka","jurka",""); Statement stmt = conn.createStatement(); stmt.execute("CREATE TEMP TABLE tts (a time, b timetz)"); long ms = Timestamp.valueOf("0001-01-01 02:02:02.0").getTime(); Timestamp timestamp = new Timestamp(ms); Time time = new Time(ms); System.out.println("Orig Values:"); System.out.println(" " + timestamp + " - " + timestamp.getTimezoneOffset() / 60); System.out.println(" " + time + " - " + time.getTimezoneOffset() / 60); PreparedStatement pstmt = conn.prepareStatement("INSERT INTO tts VALUES (?,?)"); pstmt.setTimestamp(1, timestamp); pstmt.setTimestamp(2, timestamp); pstmt.executeUpdate(); pstmt.setTime(1, time); pstmt.setTime(2, time); pstmt.executeUpdate(); pstmt.close(); ResultSet rs = stmt.executeQuery("SELECT a,b FROM tts"); while(rs.next()) { System.out.println("-------------"); for (int i=1; i<=2; i++) { System.out.println(rs.getString(i)); System.out.println(rs.getTimestamp(i) + " - " + rs.getTimestamp(i).getTimezoneOffset() / 60); System.out.println(rs.getTime(i) + " - " + rs.getTime(i).getTimezoneOffset() / 60); System.out.println(); } } rs.close(); stmt.close(); conn.close(); } }

view thread (6+ messages)  latest in thread

Message-ID: <Pine.BSO.4.56.0504140407320.17685@leary.csoft.net>
Permalink:  ../Pine.BSO.4.56.0504140407320.17685@leary.csoft.net/
Also on:    postgresql.org/message-id/Pine.BSO.4.56.0504140407320.17685@leary.csoft.net

 · 

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: books@ejurka.com, borisk@mainsoft.com
  Subject: Re: Bug in storing Timestamp
  In-Reply-To: <Pine.BSO.4.56.0504140407320.17685@leary.csoft.net>
  References: <425A701C.6070608@mainsoft.com> <Pine.BSO.4.56.0504140407320.17685@leary.csoft.net>

* 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