[BUG?] Extreme dates - Mailing list pgsql-jdbc

From ow
Subject [BUG?] Extreme dates
Date
Msg-id 20040517181733.58834.qmail@web60806.mail.yahoo.com
Whole thread Raw
Responses Re: [BUG?] Extreme dates
List 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/

pgsql-jdbc by date:

Previous
From: "Waldomiro"
Date:
Subject: Re: [BUG?] Extreme dates
Next
From: Kris Jurka
Date:
Subject: Re: [BUG?] Extreme dates