MyBatis报错:org.apache.ibatis.exceptions.PersistenceException 的解决方案

MyBatis报错控制台输出:

org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='proCode', 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 non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
### The error may exist in com/smbms/dao/provider/ProviderMapper.xml
### The error may involve com.smbms.dao.provider.ProviderMapper.addProvider-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO `smbms_provider`( `proCode`,`proName`,`proDesc`,`proContact`         ,`proPhone`,`proAddress',`proFax`,`createdBy`,`creationDate`)         VALUES(?,?,?,?,?         ,?,?,?,?,?);
### Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='proCode', 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 non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).

我们首先观察报错信息,可以发现,其中有一句提示为java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).这个提示的意思为SQL语句的参数超过了实际的数量。所以我们找到对应的SQL映射文件去找问题。如下案例:
MyBatis报错:org.apache.ibatis.exceptions.PersistenceException 的解决方案_第1张图片从上图中我们可以发现,我们实际上只需要九个参数,而后面给出了十个,所以就是这个引起了运行时异常,只要我们把多余的参数删除,就可以让程序正常运行了。
MyBatis报错:org.apache.ibatis.exceptions.PersistenceException 的解决方案_第2张图片问题被完美解决!

你可能感兴趣的:(MyBatis报错:org.apache.ibatis.exceptions.PersistenceException 的解决方案)