@@ -209,13 +209,7 @@ protected void writeSingleRecordInternal(Row row) throws WriteRecordException {
209209 int index = 0 ;
210210 try {
211211 for (; index < row .getArity (); index ++) {
212- Object object = row .getField (index );
213- if ( object instanceof String && StringUtils .isBlank ((String ) object )){
214- if (!STRING_TYPES .contains (columnType .get (index ))){
215- object = null ;
216- }
217- }
218- preparedStatement .setObject (index +1 , object );
212+ preparedStatement .setObject (index +1 , getField (row , index ));
219213 }
220214
221215 preparedStatement .execute ();
@@ -247,13 +241,7 @@ protected void writeMultipleRecordsInternal() throws Exception {
247241 try {
248242 for (Row row : rows ) {
249243 for (int index = 0 ; index < row .getArity (); index ++) {
250- Object object = row .getField (index );
251- if ( object instanceof String && StringUtils .isBlank ((String ) object )){
252- if (!STRING_TYPES .contains (columnType .get (index ))){
253- object = null ;
254- }
255- }
256- preparedStatement .setObject (index +1 , object );
244+ preparedStatement .setObject (index +1 , getField (row , index ));
257245 }
258246 preparedStatement .addBatch ();
259247
@@ -330,9 +318,23 @@ public FormatState getFormatState(){
330318 }
331319 }
332320
321+ /**
322+ * 获取转换后的字段value
323+ * @param row
324+ * @param index
325+ * @return
326+ */
333327 protected Object getField (Row row , int index ) {
334328 Object field = row .getField (index );
335329 String type = columnType .get (index );
330+
331+ //field为空字符串,且写入目标类型不为字符串类型的字段,则将object设置为null
332+ if (field instanceof String
333+ && StringUtils .isBlank ((String ) field )
334+ &&!STRING_TYPES .contains (type )){
335+ return null ;
336+ }
337+
336338 if (type .matches (DateUtil .DATE_REGEX )) {
337339 field = DateUtil .columnToDate (field ,null );
338340 } else if (type .matches (DateUtil .DATETIME_REGEX ) || type .matches (DateUtil .TIMESTAMP_REGEX )){
0 commit comments