pgjdbc/pgjdbc GitHub issues and pull requests (mirror)
help / color / mirror / Atom feedFrom: davecramer (@davecramer) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: Re: [pgjdbc/pgjdbc] issue #3924: 0001-01-01 Date not properly saved in database and not properly red from database
Date: Mon, 02 Feb 2026 14:31:11 +0000
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
Using
```
try (Connection conn = DriverManager.getConnection(url, props)) {
try (PreparedStatement ps = conn.prepareStatement("insert into example_table(d) values (?)")){
LocalDate localDate = LocalDate.of(0, 1, 1);
java.sql.Date sqlDate = java.sql.Date.valueOf(localDate);
ps.setDate(1, sqlDate);
ps.execute();
localDate = LocalDate.of (1,1,1);
sqlDate = java.sql.Date.valueOf(localDate);
ps.setDate(1, sqlDate);
ps.execute();
}
}
try ( Connection conn = DriverManager.getConnection(url, props) ){
try ( Statement statement = conn.createStatement() ) {
try (ResultSet rs = statement.executeQuery( "SELECT d FROM EXAMPLE_TABLE") ){ //Retrives value 0001-01-01 already persisted in database
while (rs.next()) {
d = rs.getDate(1);
ts = rs.getTimestamp(1);
d1 = rs.getObject(1, LocalDate.class);
//-62135751600000
System.out.println( "Get Date: " + d); //Returns 0001-01-03
System.out.println( "Get Timestamp: " + ts); //Returns 0001-01-03 00:00:00
System.out.println( "Get LocalDate: " + d1); //Returns 0001-01-01
}
}
}
}
}
```
So with 42.7.8 given a table:
```
table example_table;
id | d
----+---------------
16 | 0001-01-01 BC
17 | 0001-01-01
```
the code produces
```
Get Date: 0001-01-01
Get Timestamp: 0001-01-01 00:00:00.0
Get LocalDate: 0000-01-01
Get Date: 0001-01-01
Get Timestamp: 0001-01-01 00:00:00.0
Get LocalDate: 0001-01-01
```
which is clearly wrong as they are 2 different dates.
With 42.7.9 we get
```
table example_table;
id | d
----+---------------
18 | 0002-12-30 BC
19 | 0001-12-30 BC
```
```
Get Date: 0001-01-01
Get Timestamp: 0001-01-01 00:00:00.0
Get LocalDate: -0001-12-30
Get Date: 0001-01-01
Get Timestamp: 0001-01-01 00:00:00.0
Get LocalDate: 0000-12-30
```
Which is also clearly wrong.
view thread (9+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: github://pgjdbc/pgjdbc
Cc: [email protected], [email protected]
Subject: Re: [pgjdbc/pgjdbc] issue #3924: 0001-01-01 Date not properly saved in database and not properly red from database
In-Reply-To: <<[email protected]>>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox