Menu ▾ ▴

#1550 rs.getObject(x, LocalDateTime.class) returne incorrect values prior to 1582-10-15

version 2.5.x
open-fixed
None
5
2019-06-16
2019-06-15
No

repro code:

String connUrl = "jdbc:hsqldb:mem:memdb";

try (Connection conn = DriverManager.getConnection(connUrl)) {
    System.out.printf("Info: HSQLDB version %s%n", conn.getMetaData().getDatabaseProductVersion());
    // Info: HSQLDB version 2.5.0

    Statement st = conn.createStatement();
    st.execute("CREATE TABLE t1 (id INT PRIMARY KEY, event VARCHAR(50), occurred TIMESTAMP)");
    st.execute("INSERT INTO t1 (id, event, occurred) VALUES (1, 'Battle of Hastings', '1066-10-14 00:00:00')");
    ResultSet rs = st.executeQuery("SELECT occurred FROM t1 WHERE id=1");
    rs.next();
    LocalDateTime actual = rs.getObject(1, LocalDateTime.class);
    LocalDateTime expected = LocalDateTime.of(1066, 10, 14, 0, 0);
    System.out.printf("%s - actual: %s, expected: %s%n", 
            actual.equals(expected) ? "PASS" : "FAIL", actual, expected);
    // FAIL - actual: 1066-10-20T00:00, expected: 1066-10-14T00:00

} catch (Throwable t) {
    t.printStackTrace(System.err);
    System.exit(999);
}

Interestingly, if the column is DATE then rs.getObject(1, LocalDate.class) returns the correct date.

Discussion

  • Fred Toussi

    Fred Toussi - 2019-06-16
    • status: open --> open-fixed
    • assigned_to: Fred Toussi
     
  • Fred Toussi

    Fred Toussi - 2019-06-16

    Thanks for reporting. Fixed and committed to SVN trunk.

     
  • Gord Thompson

    Gord Thompson - 2019-06-16

    Yup. Tests with r6017 look good. Thanks, Fred!

     

Log in to post a comment.