使用MyBatis框架做更新操作時,在該字段需要更新的內容為空時,就會出現1111錯誤,也就是無效的列類型,這個時候你就要使用jdbcType。至於什么時候要使用到javaType我還沒遇到過,而且我也沒有聽說過要使用javaType。
異常顯示如下:
Exception in thread "main" org.springframework.jdbc.UncategorizedSQLException: 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 ; uncategorized SQLException for SQL []; SQL state [99999]; error code [17004]; 無效的列類型: 1111; nested exception is java.sql.SQLException: 無效的列類型: 1111
mybatis insert空值報空值異常,但是在pl/sql不會提示錯誤,主要原因是mybatis無法進行轉換,
錯誤日志是在:org.apache.ibatis.type.BaseTypeHandler這個類的第17行打出的。
if (parameter == null) { if (jdbcType == null) { try { ps.setNull(i, JdbcType.OTHER.TYPE_CODE); } catch (SQLException e) { throw new TypeException("Error setting null parameter. Most JDBC drivers require that the JdbcType must be specified for all nullable parameters. Cause: " + e, e); } } else { ps.setNull(i, jdbcType.TYPE_CODE); } } else { setNonNullParameter(ps, i, parameter, jdbcType); }
可以看出,是因為你傳入的參數的字段為null對象無法獲取對應的jdbcType類型,而報的錯誤。
你只要在insert語句中insert的對象加上jdbcType就可以了,修改如下:
#{menuTitle,jdbcType=VARCHAR}