问题:使用MyBatis-plus+Orecle的一次查询引发的报错
完整错误
There was an unexpected error (type=Internal Server Error, status=500).
nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='cardId', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #1 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型: 1111
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='cardId', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #1 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型: 1111
前提
这个是由于Orecle 数据库查询的时候参数是null (注意不是"",这个可以通过)
场景:
1:使用mybati-plus查询会出现报错
2:xml里也会报错
处理方法:
1:第一种情况直接加一个null的判断
2:第二种情况:在xml里加上对应的数据类型:如下,这里我的是字符串,加:jdbcType=VARCHAR
<select id="getInfoById" resultType="com.sinosoft.pojo.Infectioncard">
select * from infectioncard where PATIENT_NAME=#{patientName,jdbcType=VARCHAR}
</select>

当在MyBatis-Plus中使用Oracle数据库进行查询时,如果参数为null,可能会遇到内部错误,状态码500。错误信息提示无效的列类型。解决方法包括在Java代码中增加null判断,或者在XML映射文件中为参数指定jdbcType,如jdbcType=VARCHAR。确保正确处理null值可以避免此类报错。

2675

被折叠的 条评论
为什么被折叠?



