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>