[BUG?] Extreme dates

From: ow <oneway_111(at)yahoo(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Cc: books(at)ejurka(dot)com
Subject: [BUG?] Extreme dates
Date: 2004-05-17 18:17:33
Message-ID: 20040517181733.58834.qmail@web60806.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi,

> I've tried to duplicate this and have failed. It does appear that Java is
> doing something strange with the date, changing it to 11/30/0002,

Probably because months start with 0.

> Please try the attached test and see what changes are necessary to get the
> failure you describe.

The following test illustrates the issue. The output I get is:

Row number= 0 col 1= 2030-02-11 14:06:00.828 col 2=2004-05-17 14:06:00.828

public void testKillMe() throws Exception {
//--------------- cut here
Class.forName("org.postgresql.Driver");
Connection conn =
DriverManager.getConnection("jdbc:postgresql://localhost:5432/rc","testuser","");

Statement stmt = conn.createStatement();
stmt.executeUpdate("CREATE TEMP TABLE tt (aMin timestamp, aMax timestamp)");
stmt.close();

Calendar cal = Calendar.getInstance();
cal.set(2, 10, 30);
// cal.set(0, 0, 0);
java.sql.Date d = new java.sql.Date(cal.getTimeInMillis());
System.out.println("Inserting: " + d);

PreparedStatement pstmt = conn.prepareStatement("INSERT INTO tt VALUES (?,
?)");
pstmt.setTimestamp(1, new java.sql.Timestamp(d.getTime()));
pstmt.setTimestamp(2, new java.sql.Timestamp(System.currentTimeMillis()));
pstmt.executeUpdate();
pstmt.close();

stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM tt");
int i = 0;
while (rs.next()) {
System.out.println("Row number = " + i + " col 1= " + rs.getTimestamp(1) + "
col 2=" + rs.getTimestamp(2));
i++;
}
//--------------- cut here
}

Thanks



__________________________________
Do you Yahoo!?
SBC Yahoo! - Internet access at a great low price.
http://promo.yahoo.com/sbc/

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message LSanchez 2004-05-17 20:40:10 Java Test Harness
Previous Message nahum castro 2004-05-17 14:05:05 Re: [JDBC] problem with spanish characters