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>