Browse Source

fixed https://gitee.com/ghi/dbsyncer/issues/I55L0L
Oracle11g to PG14, oracle读取date数据类型为NULL

AE86 3 years ago
parent
commit
5f1f091c52

+ 11 - 0
dbsyncer-connector/src/main/java/org/dbsyncer/connector/database/setter/DateSetter.java

@@ -1,10 +1,12 @@
 package org.dbsyncer.connector.database.setter;
 
+import org.dbsyncer.connector.ConnectorException;
 import org.dbsyncer.connector.database.AbstractSetter;
 
 import java.sql.Date;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
+import java.sql.Timestamp;
 
 public class DateSetter extends AbstractSetter<Date> {
 
@@ -13,4 +15,13 @@ public class DateSetter extends AbstractSetter<Date> {
         ps.setDate(i, val);
     }
 
+    @Override
+    protected void setIfValueTypeNotMatch(PreparedFieldMapper mapper, PreparedStatement ps, int i, int type, Object val) throws SQLException {
+        if (val instanceof Timestamp) {
+            Timestamp timestamp = (Timestamp) val;
+            ps.setDate(i, Date.valueOf(timestamp.toLocalDateTime().toLocalDate()));
+            return;
+        }
+        throw new ConnectorException(String.format("DateSetter can not find type [%s], val [%s]", type, val));
+    }
 }