当MyBatis insert
或者update
语句的变量含有空值
(null值
) 时,需要指定JdbcType 否则:java.sql.SQLException: Invalid column type: 1111 无效的列类型: 1111
解决方法:给参数加上 jdbcType
可解决(注意大小写)
insert into xxx(a,b) values( #{a,jdbcType=VARCHAR}, #{b,jdbcType=DATE} ) update xxx set a=#{a,jdbcType=VARCHAR} where id=#{id}
注意:
${all}
时不适用jdbcType
a.xx like '%${all}%'
此时不能加jdbcType=VARCHAR
jdbcType类型
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(-9), // JDK6 NCHAR(-15), // JDK6 NCLOB(2011), // JDK6 STRUCT(Types.STRUCT);