src/main/java/de/uapcore/lightpit/dao/Functions.java

changeset 62
833e0385572a
parent 47
57cfb94ab99f
child 138
e2aa673dd473
--- a/src/main/java/de/uapcore/lightpit/dao/Functions.java	Sun May 17 16:38:04 2020 +0200
+++ b/src/main/java/de/uapcore/lightpit/dao/Functions.java	Mon May 18 21:05:57 2020 +0200
@@ -28,6 +28,7 @@
  */
 package de.uapcore.lightpit.dao;
 
+import java.sql.Date;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.sql.Types;
@@ -47,6 +48,14 @@
         }
     }
 
+    public static void setDateOrNull(PreparedStatement stmt, int index, Date date) throws SQLException {
+        if (date == null) {
+            stmt.setNull(index, Types.DATE);
+        } else {
+            stmt.setDate(index, date);
+        }
+    }
+
     public static <T> void setForeignKeyOrNull(PreparedStatement stmt, int index, T instance, Function<? super T, Integer> keyGetter) throws SQLException {
         Integer key = Optional.ofNullable(instance).map(keyGetter).orElse(null);
         if (key == null) {

mercurial