This commit is contained in:
agapple
2019-02-25 15:18:04 +08:00
parent 1473a4a6b5
commit 072420c32b
7 changed files with 71 additions and 63 deletions

View File

@@ -2,7 +2,12 @@ package com.alibaba.otter.canal.client.adapter.support;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.*;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import org.joda.time.DateTime;
import org.slf4j.Logger;
@@ -67,14 +72,14 @@ public class JdbcTypeUtil {
}
}
private static boolean isText(String columnType) {
return "LONGTEXT".equalsIgnoreCase(columnType) || "MEDIUMTEXT".equalsIgnoreCase(columnType)
|| "TEXT".equalsIgnoreCase(columnType) || "TINYTEXT".equalsIgnoreCase(columnType);
}
public static Object typeConvert(String columnName, String value, int sqlType, String mysqlType) {
if (value == null
|| (value.equals("")
&& !("longtext".equals(mysqlType)
|| "text".equals(mysqlType)
|| sqlType == Types.CHAR
|| sqlType == Types.VARCHAR
|| sqlType == Types.LONGVARCHAR))) {
|| (value.equals("") && !(isText(mysqlType) || sqlType == Types.CHAR || sqlType == Types.VARCHAR || sqlType == Types.LONGVARCHAR))) {
return null;
}
@@ -124,7 +129,7 @@ public class JdbcTypeUtil {
value = value.trim().replace(" ", "T");
DateTime dt = new DateTime(value);
res = new Date(dt.toDate().getTime());
break;
break;
}
case Types.TIME:
value = "T" + value;