mybatis 插入空值时报错 TypeException

时间:2020-11-27 07:32:38

报错内容:nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='transferPersitionTime', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #9 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型

之前使用的是mysql,后面转为 oracle ,切换之后插入数据就报错

插入空值时需要制定类型

所以我们指定类型就好了

insert into
clean_user(id,status,update_time,mip,emp_name,emp_code,old_unit_code,old_unit_name,new_unit_code,new_unit_name,transfer_persition_time,erp_uid,backup1,backup2,backup3)
values(
SYS_GUID(),
#{status,jdbcType=VARCHAR},
#{updateTime,jdbcType=TIMESTAMP},
#{mip,jdbcType=VARCHAR},
#{empName,jdbcType=VARCHAR},
#{empCode,jdbcType=VARCHAR},
#{oldUnitCode,jdbcType=VARCHAR},
#{oldUnitName,jdbcType=VARCHAR},
#{newUnitCode,jdbcType=VARCHAR},
#{newUnitName,jdbcType=VARCHAR},
#{transferPersitionTime,jdbcType=VARCHAR},
#{erpUid,jdbcType=VARCHAR},
#{backup1,jdbcType=VARCHAR},
#{backup2,jdbcType=VARCHAR},
#{backup3,jdbcType=VARCHAR}
)

  有什么类型呢,查看 org.apache.ibatis.type.JdbcType.java 就可以看到了。

 ARRAY(Types.ARRAY),
BIT(Types.BIT),
TINYINT(Types.TINYINT),
SMALLINT(Types.SMALLINT),
INTEGER(Types.INTEGER),
BIGINT(Types.BIGINT),
FLOAT(Types.FLOAT),
REAL(Types.REAL),
DOUBLE(Types.DOUBLE),
NUMERIC(Types.NUMERIC),
DECIMAL(Types.DECIMAL),
CHAR(Types.CHAR),
VARCHAR(Types.VARCHAR),
LONGVARCHAR(Types.LONGVARCHAR),
DATE(Types.DATE),
TIME(Types.TIME),
TIMESTAMP(Types.TIMESTAMP),
BINARY(Types.BINARY),
VARBINARY(Types.VARBINARY),
LONGVARBINARY(Types.LONGVARBINARY),
NULL(Types.NULL),
OTHER(Types.OTHER),
BLOB(Types.BLOB),
CLOB(Types.CLOB),
BOOLEAN(Types.BOOLEAN),
CURSOR(-10), // Oracle
UNDEFINED(Integer.MIN_VALUE + 1000),
NVARCHAR(Types.NVARCHAR), // JDK6
NCHAR(Types.NCHAR), // JDK6
NCLOB(Types.NCLOB), // JDK6
STRUCT(Types.STRUCT);