From 484ed90b7c8561b70490a2aec17243bf8e8cef84 Mon Sep 17 00:00:00 2001 From: Jakub Holy Date: Mon, 18 Nov 2019 15:27:11 +0100 Subject: [PATCH] Fix next.jdbc.date-time for java.sql.Date An insert fails with > UnsupportedOperationException: null at java.sql/java.sql.Date.toInstant(Date.java:316) if you required `next.jdbc.date-time` and the value you are inserting is `java.sql.Date` because it is a subclass of `java.util.Date` and thus gets handled by https://github.com/seancorfield/next-jdbc/blob/master/src/next/jdbc/date_time.clj#L45 - but it doesn't support `toInstant` contrary to its superclass. The solution is to use `.setDate` with the value as-is instead of `.setTimestamp`. --- src/next/jdbc/date_time.clj | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/next/jdbc/date_time.clj b/src/next/jdbc/date_time.clj index 09b20c9..14b9927 100644 --- a/src/next/jdbc/date_time.clj +++ b/src/next/jdbc/date_time.clj @@ -44,4 +44,8 @@ ;; this is just to help PostgreSQL: java.util.Date (set-parameter [^java.util.Date v ^PreparedStatement s ^long i] - (.setTimestamp s i (Timestamp/from (.toInstant v))))) + (.setTimestamp s i (Timestamp/from (.toInstant v)))) + ;; ... but leave java.*sql*.Date as-is, it doesn't support toInstant + java.sql.Date + (set-parameter [^java.sql.Date v ^PreparedStatement s ^long i] + (.setDate s i v)))