mybatis什么时候必须指定jdbcType
#{property, jdbcType=VARCHAR}
如果一个列允许 null 值,并且会传递值 null 的参数,就必须要指定 JDBC Type
如果是一个可以为null的字段,在insert的时候,没有给该字段赋值,mybatis就会报下面的错误
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='__frch_item_0.defaultValue', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #6 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型: 1111
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
Caused by: org.apache.ibatis.type.TypeException: Error setting null for parameter #6 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型: 1111
at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:47)
at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:87)
... 54 more
Caused by: java.sql.SQLException: 无效的列类型: 1111
Mybatis中 javaType 和 jdbcType 对应关系
JDBCType JavaType
CHAR String
VARCHAR String
LONGVARCHAR String
NUMERIC java.math.BigDecimal
DECIMAL java.math.BigDecimal
BIT boolean
BOOLEAN boolean
TINYINT byte
SMALLINT short
INTEGER int
BIGINT long
REAL float
FLOAT double
DOUBLE double
BINARY byte[]
VARBINARY byte[]
LONGVARBINARY byte[]
DATE java.sql.Date
TIME java.sql.Time
TIMESTAMP java.sql.Timestamp
CLOB Clob
BLOB Blob
ARRAY Array
DISTINCT mapping of underlying type
STRUCT Struct
REF Ref
DATALINK java.net.URL
Mybatis JdbcType与Oracle、MySql数据类型对
Mybatis | JdbcType | Oracle | MySql |
---|---|---|---|
JdbcType | ARRAY | ||
JdbcType | BIGINT | BIGINT | |
JdbcType | BINARY | ||
JdbcType | BIT | BIT | |
JdbcType | BLOB | BLOB | BLOB |
JdbcType | BOOLEAN | ||
JdbcType | CHAR | CHAR | CHAR |
JdbcType | CLOB | CLOB | TEXT |
JdbcType | CURSOR | ||
JdbcType | DATE | DATE | DATE |
JdbcType | DECIMAL | DECIMAL | DECIMAL |
JdbcType | DOUBLE | NUMBER | DOUBLE |
JdbcType | FLOAT | FLOAT | FLOAT |
JdbcType | INTEGER | INTEGER | INTEGER |
JdbcType | LONGVARBINARY | ||
JdbcType | LONGVARCHAR | LONG VARCHAR | |
JdbcType | NCHAR | NCHAR | |
JdbcType | NCLOB | NCLOB | |
JdbcType | NULL | ||
JdbcType | NUMERIC | NUMERIC/NUMBER | NUMERIC/ |
JdbcType | NVARCHAR | ||
JdbcType | OTHER | ||
JdbcType | REAL | REAL | REAL |
JdbcType | SMALLINT | SMALLINT | SMALLINT |
JdbcType | STRUCT | ||
JdbcType | TIME | TIME | |
JdbcType | TIMESTAMP | TIMESTAMP | TIMESTAMP/DATETIME |
JdbcType | TINYINT | TINYINT | |
JdbcType | UNDEFINED | ||
JdbcType | VARBINARY | ||
JdbcType | VARCHAR | VARCHAR | VARCHAR |