pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedRe: Strange behaviour of rs.getTimestamp
8+ messages / 5 participants
[nested] [flat]
* Re: Strange behaviour of rs.getTimestamp
@ 2011-01-06 14:22 Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-06 14:50 ` Re: Strange behaviour of rs.getTimestamp Altaf Malik <mmalik_altaf@yahoo.com>
0 siblings, 1 reply; 8+ messages in thread
From: Kevin Grittner @ 2011-01-06 14:22 UTC (permalink / raw)
To: pgsql-jdbc; Altaf Malik <mmalik_altaf@yahoo.com>
Altaf Malik <mmalik_altaf@yahoo.com> wrote:
> I get correct values if I run the same test case against JDK 1.5
As opposed to what? (You never really told us about the environment
in which you're seeing the failure.)
> (However I have noticed the same behaviour on some of the JDK
> 1.5's on our network)
So, what's different between the ones that yield the correct values
and the ones that don't? (Obviously you're in a better position to
determine that than I am.)
You might get some ideas on additional information you could include
to get better support from this page:
http://wiki.postgresql.org/wiki/Guide_to_reporting_problems
If you can put together a self-contained test case that someone can
compile and run on their own machine, it becomes much easier for
others to understand the problem and to help.
-Kevin
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Strange behaviour of rs.getTimestamp
2011-01-06 14:22 Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
@ 2011-01-06 14:50 ` Altaf Malik <mmalik_altaf@yahoo.com>
2011-01-06 14:56 ` Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
0 siblings, 1 reply; 8+ messages in thread
From: Altaf Malik @ 2011-01-06 14:50 UTC (permalink / raw)
To: Kevin Grittner <Kevin.Grittner@wicourts.gov>; pgsql-jdbc
> So, what's different between the ones that yield the correct values
> and the ones that don't?
Please look at the values:
2009-04-15 00:00:00->2009-04-15 01:00:00.0
The value I inserted in table was 2009-04-15 00:00:00 and from rs.getString(1) I
got the same value. rs.getTimestamp(1) returned me a different value (note the
hour value is 1 instead of 0). The value I got is: 2009-04-15 00:00:00
> If you can put together a self-contained test case that someone can
> compile and run on their own machine, it becomes much easier for
> others to understand the problem and to help.
I did so. Please read the following portion carefully:
Statement stmt = con.createStatement();
stmt.executeUpdate("create table ts_test(a timestamp)");
stmt.executeUpdate("insert into ts_test values('15-APR-09');");
ResultSet rs = stmt.executeQuery("select * from ts_test");
while (rs.next()) {
Timestamp t = rs.getTimestamp(1);
System.out.println(rs.getString(1)+"->"+ t);
}
stmt.executeUpdate("drop table ts_test");
Regards,
Altaf Malik
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Strange behaviour of rs.getTimestamp
2011-01-06 14:22 Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-06 14:50 ` Re: Strange behaviour of rs.getTimestamp Altaf Malik <mmalik_altaf@yahoo.com>
@ 2011-01-06 14:56 ` Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-06 20:46 ` Re: Strange behaviour of rs.getTimestamp Samuel Gendler <sgendler@ideasculptor.com>
0 siblings, 1 reply; 8+ messages in thread
From: Kevin Grittner @ 2011-01-06 14:56 UTC (permalink / raw)
To: pgsql-jdbc; Altaf Malik <mmalik_altaf@yahoo.com>
Altaf Malik <mmalik_altaf@yahoo.com> wrote:
>> So, what's different between the ones that yield the correct
>> values and the ones that don't?
>
> Please look at the values:
> 2009-04-15 00:00:00->2009-04-15 01:00:00.0
You didn't read very closely -- you said some machines gave the
right answer and some the wrong answer. Clearly there's something
different from one to the other. What?
>> If you can put together a self-contained test case that someone
>> can compile and run on their own machine, it becomes much easier
>> for others to understand the problem and to help.
>
> I did so. Please read the following portion carefully:
No, that was a code snippet. I fleshed it out to a compilable
source file like this:
import java.sql.*;
public final class TestTS
{
public static void main(String[] args) throws Exception
{
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection
("jdbc:postgresql:test", "test", "test");
Statement stmt = con.createStatement();
stmt.executeUpdate("create table ts_test(a timestamp)");
stmt.executeUpdate
("insert into ts_test values('15-APR-09');");
ResultSet rs = stmt.executeQuery("select * from ts_test");
System.out.println(System.getProperty("java.vendor"));
System.out.println(System.getProperty("java.version"));
System.out.println(System.getProperty("java.vm.name"));
System.out.println(System.getProperty("java.vm.info"));
while (rs.next()) {
Timestamp t = rs.getTimestamp(1);
System.out.println(rs.getString(1)+"->"+ t);
}
rs.close();
stmt.executeUpdate("drop table ts_test");
stmt.close();
con.close();
}
}
When I compile and run, I get this:
Sun Microsystems Inc.
1.6.0_21
Java HotSpot(TM) Client VM
mixed mode, sharing
2009-04-15 00:00:00->2009-04-15 00:00:00.0
Unless you provide more information, nobody can help.
-Kevin
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Strange behaviour of rs.getTimestamp
2011-01-06 14:22 Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-06 14:50 ` Re: Strange behaviour of rs.getTimestamp Altaf Malik <mmalik_altaf@yahoo.com>
2011-01-06 14:56 ` Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
@ 2011-01-06 20:46 ` Samuel Gendler <sgendler@ideasculptor.com>
2011-01-06 21:00 ` Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
0 siblings, 1 reply; 8+ messages in thread
From: Samuel Gendler @ 2011-01-06 20:46 UTC (permalink / raw)
To: Kevin Grittner <Kevin.Grittner@wicourts.gov>; +Cc: pgsql-jdbc@postgresql.org, Altaf Malik <mmalik_altaf@yahoo.com>
On Thu, Jan 6, 2011 at 6:56 AM, Kevin Grittner
<Kevin.Grittner@wicourts.gov>wrote:
>
>
> Unless you provide more information, nobody can help.
>
>
It might also be potentially revealing if you print out the default timezone
and locale for the jvm in question as well.
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Strange behaviour of rs.getTimestamp
2011-01-06 14:22 Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-06 14:50 ` Re: Strange behaviour of rs.getTimestamp Altaf Malik <mmalik_altaf@yahoo.com>
2011-01-06 14:56 ` Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-06 20:46 ` Re: Strange behaviour of rs.getTimestamp Samuel Gendler <sgendler@ideasculptor.com>
@ 2011-01-06 21:00 ` Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-07 15:31 ` Re: Strange behaviour of rs.getTimestamp Altaf Malik <mmalik_altaf@yahoo.com>
0 siblings, 1 reply; 8+ messages in thread
From: Kevin Grittner @ 2011-01-06 21:00 UTC (permalink / raw)
To: Altaf Malik <mmalik_altaf@yahoo.com>; +Cc: Samuel Gendler <sgendler@ideasculptor.com>; pgsql-jdbc
Samuel Gendler <sgendler@ideasculptor.com> wrote:
> It might also be potentially revealing if you print out the
> default timezone and locale for the jvm in question as well.
Good point. In addition to the system properties printed from what
I posted, please include the "user.timezone" system property.
-Kevin
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Strange behaviour of rs.getTimestamp
2011-01-06 14:22 Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-06 14:50 ` Re: Strange behaviour of rs.getTimestamp Altaf Malik <mmalik_altaf@yahoo.com>
2011-01-06 14:56 ` Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-06 20:46 ` Re: Strange behaviour of rs.getTimestamp Samuel Gendler <sgendler@ideasculptor.com>
2011-01-06 21:00 ` Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
@ 2011-01-07 15:31 ` Altaf Malik <mmalik_altaf@yahoo.com>
2011-01-07 16:54 ` Re: Strange behaviour of rs.getTimestamp Radosław Smogura <rsmogura@softperience.eu>
0 siblings, 1 reply; 8+ messages in thread
From: Altaf Malik @ 2011-01-07 15:31 UTC (permalink / raw)
To: Kevin Grittner <Kevin.Grittner@wicourts.gov>; +Cc: Samuel Gendler <sgendler@ideasculptor.com>; pgsql-jdbc
Here is the output of the program run. I also included user.timezone
Sun Microsystems Inc.
1.6.0_21
Java HotSpot(TM) 64-Bit Server VM
mixed mode
TimeZone:Asia/Karachi
2009-04-15 00:00:00->2009-04-15 01:00:00.0
I am using UBUNTU 10.10 64 bit.
I don't see this behaviour with other timezones. For example, I set my TZ to
PST, GMT and the values were correct.
I debugged little further and found that the value is changed in the following
code:
Calendar c = new GregorianCalendar();
c.set(Calendar.ERA, 1);
c.set(Calendar.YEAR, 2009);
c.set(Calendar.MONTH, 4-1);
c.set(Calendar.DAY_OF_MONTH, 15);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
Timestamp ts = new Timestamp(c.getTime().getTime());
In the specific scenario, if you print ts, it shows hour value as 1 only on
this specific date. So obviously, something seems wrong with JDK or my timezone
data.
My point is, that when we don't want the value interpreted in different
timezones (we are using timestamp and not timestamp with timezone), we should
not use Calander to convert value to a timestamp when we exactly have
year,month,day,hour,minute and second values.
-- Altaf Malik
________________________________
From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: Altaf Malik <mmalik_altaf@yahoo.com>
Cc: Samuel Gendler <sgendler@ideasculptor.com>; pgsql-jdbc@postgresql.org
Sent: Fri, January 7, 2011 2:00:55 AM
Subject: Re: [JDBC] Strange behaviour of rs.getTimestamp
Samuel Gendler <sgendler@ideasculptor.com> wrote:
> It might also be potentially revealing if you print out the
> default timezone and locale for the jvm in question as well.
Good point. In addition to the system properties printed from what
I posted, please include the "user.timezone" system property.
-Kevin
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Strange behaviour of rs.getTimestamp
2011-01-06 14:22 Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-06 14:50 ` Re: Strange behaviour of rs.getTimestamp Altaf Malik <mmalik_altaf@yahoo.com>
2011-01-06 14:56 ` Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-06 20:46 ` Re: Strange behaviour of rs.getTimestamp Samuel Gendler <sgendler@ideasculptor.com>
2011-01-06 21:00 ` Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-07 15:31 ` Re: Strange behaviour of rs.getTimestamp Altaf Malik <mmalik_altaf@yahoo.com>
@ 2011-01-07 16:54 ` Radosław Smogura <rsmogura@softperience.eu>
2011-01-07 18:49 ` Re: Strange behaviour of rs.getTimestamp Radosław Smogura <mail@smogura.eu>
0 siblings, 1 reply; 8+ messages in thread
From: Radosław Smogura @ 2011-01-07 16:54 UTC (permalink / raw)
To: pgsql-jdbc; +Cc: Altaf Malik <mmalik_altaf@yahoo.com>; Kevin Grittner <Kevin.Grittner@wicourts.gov>; Samuel Gendler <sgendler@ideasculptor.com>
Hi,
I think it's DST maybe you missed something. I didn't search deaply.
https://bugzilla.redhat.com/show_bug.cgi?id=495473
Did you missed something, about DST?
Kind regards,
Radosław Smogura
http://softperience.eu
Altaf Malik <mmalik_altaf@yahoo.com> Friday 07 January 2011 16:31:26
> Here is the output of the program run. I also included user.timezone
>
> Sun Microsystems Inc.
> 1.6.0_21
> Java HotSpot(TM) 64-Bit Server VM
> mixed mode
> TimeZone:Asia/Karachi
> 2009-04-15 00:00:00->2009-04-15 01:00:00.0
>
> I am using UBUNTU 10.10 64 bit.
> I don't see this behaviour with other timezones. For example, I set my TZ
> to PST, GMT and the values were correct.
>
>
> I debugged little further and found that the value is changed in the
> following code:
>
> Calendar c = new GregorianCalendar();
> c.set(Calendar.ERA, 1);
> c.set(Calendar.YEAR, 2009);
> c.set(Calendar.MONTH, 4-1);
> c.set(Calendar.DAY_OF_MONTH, 15);
> c.set(Calendar.HOUR_OF_DAY, 0);
> c.set(Calendar.MINUTE, 0);
> c.set(Calendar.SECOND, 0);
> c.set(Calendar.MILLISECOND, 0);
> Timestamp ts = new Timestamp(c.getTime().getTime());
>
> In the specific scenario, if you print ts, it shows hour value as 1 only
> on this specific date. So obviously, something seems wrong with JDK or my
> timezone data.
>
> My point is, that when we don't want the value interpreted in different
> timezones (we are using timestamp and not timestamp with timezone), we
> should not use Calander to convert value to a timestamp when we exactly
> have year,month,day,hour,minute and second values.
>
> -- Altaf Malik
>
>
>
> ________________________________
> From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
> To: Altaf Malik <mmalik_altaf@yahoo.com>
> Cc: Samuel Gendler <sgendler@ideasculptor.com>; pgsql-jdbc@postgresql.org
> Sent: Fri, January 7, 2011 2:00:55 AM
> Subject: Re: [JDBC] Strange behaviour of rs.getTimestamp
>
> Samuel Gendler <sgendler@ideasculptor.com> wrote:
> > It might also be potentially revealing if you print out the
> > default timezone and locale for the jvm in question as well.
>
> Good point. In addition to the system properties printed from what
> I posted, please include the "user.timezone" system property.
>
> -Kevin
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Strange behaviour of rs.getTimestamp
2011-01-06 14:22 Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-06 14:50 ` Re: Strange behaviour of rs.getTimestamp Altaf Malik <mmalik_altaf@yahoo.com>
2011-01-06 14:56 ` Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-06 20:46 ` Re: Strange behaviour of rs.getTimestamp Samuel Gendler <sgendler@ideasculptor.com>
2011-01-06 21:00 ` Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-07 15:31 ` Re: Strange behaviour of rs.getTimestamp Altaf Malik <mmalik_altaf@yahoo.com>
2011-01-07 16:54 ` Re: Strange behaviour of rs.getTimestamp Radosław Smogura <rsmogura@softperience.eu>
@ 2011-01-07 18:49 ` Radosław Smogura <mail@smogura.eu>
0 siblings, 0 replies; 8+ messages in thread
From: Radosław Smogura @ 2011-01-07 18:49 UTC (permalink / raw)
To: pgsql-jdbc; +Cc: Altaf Malik <mmalik_altaf@yahoo.com>; Kevin Grittner <Kevin.Grittner@wicourts.gov>; Samuel Gendler <sgendler@ideasculptor.com>
Sorry, but for P. S.
It's quite good response, because, in your timezone, and in all other
timezones when DST starts there is no hour and times in your e.g. 2009-14-15
0:00:00 till 2099-14-15 1:00:00. At midnight you add one hour to all clocks.
So just after 2009-14-14 23:59:59.9999999. you have 2009-14-15 1:0:0.
As you use Timestamps, Java internaly stores time in UTC, and when You cast
this to String, then Calendar will rollover such fields to next Value (see
setLenient(bool)).
Unfortunatly Pakistan Gover, choosed realy bed time for DST, if this would be
1 AM, you have no problem.
Radosław Smogura <rsmogura@softperience.eu> Friday 07 January 2011 17:54:51
> Hi,
> I think it's DST maybe you missed something. I didn't search deaply.
> https://bugzilla.redhat.com/show_bug.cgi?id=495473
>
> Did you missed something, about DST?
>
> Kind regards,
> Radosław Smogura
> http://softperience.eu
>
> Altaf Malik <mmalik_altaf@yahoo.com> Friday 07 January 2011 16:31:26
>
> > Here is the output of the program run. I also included user.timezone
> >
> > Sun Microsystems Inc.
> > 1.6.0_21
> > Java HotSpot(TM) 64-Bit Server VM
> > mixed mode
> > TimeZone:Asia/Karachi
> > 2009-04-15 00:00:00->2009-04-15 01:00:00.0
> >
> > I am using UBUNTU 10.10 64 bit.
> > I don't see this behaviour with other timezones. For example, I set my TZ
> > to PST, GMT and the values were correct.
> >
> >
> > I debugged little further and found that the value is changed in the
> >
> > following code:
> > Calendar c = new GregorianCalendar();
> >
> > c.set(Calendar.ERA, 1);
> > c.set(Calendar.YEAR, 2009);
> > c.set(Calendar.MONTH, 4-1);
> > c.set(Calendar.DAY_OF_MONTH, 15);
> > c.set(Calendar.HOUR_OF_DAY, 0);
> > c.set(Calendar.MINUTE, 0);
> > c.set(Calendar.SECOND, 0);
> >
> > c.set(Calendar.MILLISECOND, 0);
> >
> > Timestamp ts = new Timestamp(c.getTime().getTime());
> >
> > In the specific scenario, if you print ts, it shows hour value as 1 only
> > on this specific date. So obviously, something seems wrong with JDK or
> > my timezone data.
> >
> > My point is, that when we don't want the value interpreted in different
> > timezones (we are using timestamp and not timestamp with timezone), we
> > should not use Calander to convert value to a timestamp when we exactly
> > have year,month,day,hour,minute and second values.
> >
> > -- Altaf Malik
> >
> >
> >
> > ________________________________
> > From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
> > To: Altaf Malik <mmalik_altaf@yahoo.com>
> > Cc: Samuel Gendler <sgendler@ideasculptor.com>; pgsql-jdbc@postgresql.org
> > Sent: Fri, January 7, 2011 2:00:55 AM
> > Subject: Re: [JDBC] Strange behaviour of rs.getTimestamp
> >
> > Samuel Gendler <sgendler@ideasculptor.com> wrote:
> > > It might also be potentially revealing if you print out the
> > > default timezone and locale for the jvm in question as well.
> >
> > Good point. In addition to the system properties printed from what
> > I posted, please include the "user.timezone" system property.
> >
> > -Kevin
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2011-01-07 18:49 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-01-06 14:22 Re: Strange behaviour of rs.getTimestamp Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-06 14:50 ` Altaf Malik <mmalik_altaf@yahoo.com>
2011-01-06 14:56 ` Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-06 20:46 ` Samuel Gendler <sgendler@ideasculptor.com>
2011-01-06 21:00 ` Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-01-07 15:31 ` Altaf Malik <mmalik_altaf@yahoo.com>
2011-01-07 16:54 ` Radosław Smogura <rsmogura@softperience.eu>
2011-01-07 18:49 ` Radosław Smogura <mail@smogura.eu>
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