problem with dates when using a java calendar object with a non-default timezone

From: Jair da Silva Ferreira Jr <j2(at)amazon(dot)com(dot)br>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: problem with dates when using a java calendar object with a non-default timezone
Date: 2004-10-13 23:26:09
Message-ID: 416DB991.3060809@amazon.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi,
I am experiencing the following problem with postgresql: the date
value I insert into the database is different from the value I select
from the database. I use a Calendar with a non-default timezone to set
and get the date value (using methods
PreparedStatement.setDate(int,Date,Calendar) and
ResultSet.getDate(int,Calendar)).
Do you know how can I fix this problem? Am I doing anything wrong?
Here is my system configuration:
Server:
OS: Red Hat Linux 7.3
Database: PostgreSQL 7.2
Client:
OS: Windows XP SP2
Java: JDK 1.4.2_05
PostgreSQL JDBC: pg72jdbc2.jar
<http://jdbc.postgresql.org/download/pg72jdbc2.jar> and
pg74.215.jdbc3.jar
<http://jdbc.postgresql.org/download/pg74.215.jdbc3.jar> (the problem
happened in both versions)

I wrote a small Java program that shows the problem. This program is
attached in this email.
Above is the program output when executed in my client system. As
you can see, "date (0) inserted" is different from "date (0) loaded",
"date (2) inserted" is different from "date (2) loaded". This is exactly
the problem. I don't care about the time (hour, minute and second)
difference as this is a SQL DATE type. The problem is that the days in
these dates are different.

//program output start
date (0) inserted: 13/10/04 00:00
date (1) inserted: 13/10/04 23:59
date (2) inserted: 13/10/04 08:00
date (3) inserted: 13/10/04 19:00
date (0) loaded: 12/10/04 17:00
date (1) loaded: 13/10/04 17:00
date (2) loaded: 12/10/04 17:00
date (3) loaded: 13/10/04 17:00
**********************************
=========
hour: 0
minute: 0
second: 0
millisecond: 0
=========
hour: 17
minute: 0
second: 0
millisecond: 0
=========
year1: 2004; month1: 9; date1: 13
year2: 2004; month2: 9; date2: 12
dates equals? false
**********************************
=========
hour: 23
minute: 59
second: 59
millisecond: 999
=========
hour: 17
minute: 0
second: 0
millisecond: 0
=========
year1: 2004; month1: 9; date1: 13
year2: 2004; month2: 9; date2: 13
dates equals? true
**********************************
=========
hour: 8
minute: 0
second: 0
millisecond: 0
=========
hour: 17
minute: 0
second: 0
millisecond: 0
=========
year1: 2004; month1: 9; date1: 13
year2: 2004; month2: 9; date2: 12
dates equals? false
**********************************
=========
hour: 19
minute: 0
second: 0
millisecond: 0
=========
hour: 17
minute: 0
second: 0
millisecond: 0
=========
year1: 2004; month1: 9; date1: 13
year2: 2004; month2: 9; date2: 13
dates equals? true
//program output end

Any help would be much appreciated.

Thanks,
Jair Jr

Attachment Content-Type Size
JDBCTest2.java text/plain 4.3 KB

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Ulrich Meis 2004-10-14 00:24:56 Re: A solution to the SSL customizing problem
Previous Message Oliver Jowett 2004-10-13 23:13:37 Re: tightening up on use of oid 0