mybatis+oracle异常1:attempted to return null from a method with a primitive return type (int).
<select id="selectNum" resultType="java.lang.Integer">
select count(1) from DSSHSJ
</select>
原因:返回值类型为Integer,但是查询出来的结果有空值,所以会出现如上的异常;更正如下:
<select id="selectNum" resultType="java.lang.Integer">
select nvl(count(1),0) from DSSHSJ
</select>
附:mysql语法中没nvl(),但有ifnull()
mybatis+oracle异常2:Oracle ORA-00913: 值过多
原因:插入时,values比字段名多了一个;
附:<if test="字段!=null">中间的字段,是java实体中的字段名,不是数据库表的字段名
mybatis+oracle异常3:Invalid bound statement (not found)
<mapper namespace="com.xxx.mapper.xxxDAO">
原因:xml与DAO映射写错
mybatis+oracle异常4:sql有多个入参,且类型不同;
解决方法1:map
Map<String, Object> glkymap=new HashMap<String,Object>();
glkymap.put("id", id);
glkymap.put("endId", endId);
glkymap.put("qxbs", qxbs);
List<TGlGlkygpxx> selectById(Map glkymap);
<select id="selectById" parameterType="Map" resultMap="实体Map">
select * from T_GL where id>#{id} and id<#{endId} and qxbs=#{qxbs}
</select>
解决方法2:@Param注解
Integer selectNum(@Param("qxbs")String qxbs);
<select id="selectNum" resultType="java.lang.Integer">
select nvl(count(1),0) from DSSHSJ where XZQHDM =#{qxbs}
</select>
这篇博客详细梳理了MyBatis在Oracle环境中遇到的四种常见异常,包括:尝试从返回基本类型(int)的方法中返回null、ORA-00913值过多错误、找不到绑定的声明异常以及SQL参数类型不一致的问题。并提供了相应的解决方案,如检查返回值类型、确认插入值与字段数量匹配、修正XML与DAO映射,以及使用Map或@Param注解处理不同类型的参数。

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



