mybatis持久化操作时,如果插入数据为null的情况下,由于内部机制问题,会导致报错,导致出现:“无效的类型:1111”示例如下:
org.springframework.jdbc.UncategorizedSQLException: Error setting null parameter. Most JDBC drivers require that the JdbcType must be specified for all nullable parameters. Cause: java.sql.SQLException: 无效的列类型: 1111 ; uncategorized SQLException for SQL []; SQL state [99999]; error code [17004]; 无效的列类型: 1111; nested exception is java.sql.SQLException: 无效的列类型: 1111 at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:71) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:360) at $Proxy10.update(Unknown Source)
解决方案:数据库插入、更新操作需要对where后条件做处理具体处理示例如下:
<insert id="insert" parameterType="daSysYgtbl">
insert into
DA_SYS_YGTBL(
ygId,
ygName,
ygDm,
sortId,
passWord,
PHONE,
TEL,
loginXz,
ipMac,
STATUS
)VALUES (
#{ygId,jdbcType=NUMBER},
#{ygName,jdbcType=VARCHAR},
#{ygDm,jdbcType=VARCHAR},
#{sortId,jdbcType=VARCHAR},
#{passWord,jdbcType=VARCHAR},
#{phone,jdbcType=VARCHAR},
#{tel,jdbcType=VARCHAR},
#{loginXz,jdbcType=VARCHAR},
#{ipMac,jdbcType=VARCHAR},
#{status,jdbcType=VARCHAR}
)
</insert>
<update id="update" parameterType="daSysYgtbl">
UPDATE DA_SYS_YGTBL
<set>
<if test="ygId!=null and ygId!=''">
ygId = #{ygId,jdbcType=NUMBER},
</if>
<if test="ygName!=null and ygName!=''">
ygName = #{ygName,jdbcType=VARCHAR},
</if>
<if test="ygDm!=null and ygDm!=''">
ygDm = #{ygDm,jdbcType=VARCHAR},
</if>
<if test="sortId!=null and sortId!=''">
sortId = #{sortId,jdbcType=VARCHAR},
</if>
<if test="passWord!=null and passWord!=''">
passWord = #{passWord,jdbcType=VARCHAR},
</if>
<if test="phone!=null and phone!=''">
PHONE = #{phone,jdbcType=VARCHAR},
</if>
<if test="tel!=null and tel!=''">
TEL = #{tel,jdbcType=VARCHAR},
</if>
<if test="loginXz!=null and loginXz!=''">
loginXz = #{loginXz,jdbcType=VARCHAR},
</if>
<if test="ipMac!=null and ipMac!=''">
ipMac = #{ipMac,jdbcType=VARCHAR},
</if>
<if test="status!=null and status!=''">
STATUS = #{status,jdbcType=VARCHAR}
</if>
</set>
WHERE ygId = #{ygId}
</update>