再用MyBatis操做Oracle的時候,傳入null值而引起的錯誤java
異常信息:spring
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: 無效的列類型 ;
uncategorized SQLException for SQL []; SQL state [null]; error code [17004];
無效的列類型; nested exception is java.sql.SQLException: 無效的列類型
當咱們用MyBatis操做數據庫的時候傳入null值,並且沒有加入jdbcType類型的時候就會引起上述這種錯誤類型,sql
由於MyBatis不知道這個地方要傳入什麼什麼參數數據庫
解決方案:ide
1.ui
單個配置
直接在後面加上 jdbcType=類型
#{id,jdbcType=VARCHAR}
2.this
全局配置spa
在MyBaits的核心配置文件裏面進行配置 <configuration> <settings> <setting name="jdbcTypeForNull" value="NULL"/> </settings> </configuration>
第二種配置方式官方是這樣解釋的:code
Specifies the JDBC type for null values when no specific JDBC type was provided for the parameter. Some drivers require specifying the column JDBC type but others work with generic values like NULL, VARCHAR or OTHER.
當沒有爲參數提供特定的JDBC類型時,指定的jdbc類型爲空。一些驅動程序須要指定列JDBC類型,但其餘驅動程序使用NULL、VARCHAR或其它類型值。