diff --git a/src/main/java/org/duckdb/DuckDBTimestamp.java b/src/main/java/org/duckdb/DuckDBTimestamp.java index f3a72028..3afbae8a 100644 --- a/src/main/java/org/duckdb/DuckDBTimestamp.java +++ b/src/main/java/org/duckdb/DuckDBTimestamp.java @@ -4,6 +4,7 @@ import java.sql.Time; import java.sql.Timestamp; import java.time.Instant; +import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.OffsetDateTime; @@ -108,6 +109,8 @@ public static Object valueOf(Object x) { x = new DuckDBTimestamp((Timestamp) x); } else if (x instanceof LocalDateTime) { x = new DuckDBTimestamp((LocalDateTime) x); + } else if (x instanceof LocalDate) { + x = new DuckDBDate(Date.valueOf((LocalDate) x)); } else if (x instanceof OffsetDateTime) { x = new DuckDBTimestampTZ((OffsetDateTime) x); } else if (x instanceof Date) { diff --git a/src/test/java/org/duckdb/TestDuckDBJDBC.java b/src/test/java/org/duckdb/TestDuckDBJDBC.java index 607fde79..3e3fc6f3 100644 --- a/src/test/java/org/duckdb/TestDuckDBJDBC.java +++ b/src/test/java/org/duckdb/TestDuckDBJDBC.java @@ -894,6 +894,9 @@ public static void test_duckdb_localdate() throws Exception { PreparedStatement ps1 = conn.prepareStatement("INSERT INTO x VALUES (?)"); ps1.setObject(1, date); ps1.execute(); + + ps1.setObject(1, ld); + ps1.execute(); ps1.close(); PreparedStatement ps2 = conn.prepareStatement("SELECT * FROM x"); @@ -904,6 +907,11 @@ public static void test_duckdb_localdate() throws Exception { assertEquals(rs2.getObject(1, LocalDate.class), ld); assertEquals(rs2.getObject("dt", LocalDate.class), ld); + rs2.next(); + assertEquals(rs2.getDate(1), rs2.getObject(1, Date.class)); + assertEquals(rs2.getObject(1, LocalDate.class), ld); + assertEquals(rs2.getObject("dt", LocalDate.class), ld); + rs2.close(); ps2.close(); stmt.close();