MyBatis调用存储过程返回结果集

存储过程:

create or replace procedure get_result_by_sql(p_sql in varchar2,p_result out sys_refcursor,p_msg out varchar2) is
begin
  open p_result for p_sql;
  p_msg := '执行SQL成功了';
EXCEPTION
  WHEN OTHERS THEN
    p_msg := '执行SQL出错了';
end get_result_by_sql;

Mbatis配置:

<resultMap id="getResultBySQLMap" type="com.hotesion.pojo.testVO">
    <result column="id" jdbcType="DECIMAL" property="id" />
    <result column="key" jdbcType="VARCHAR" property="key" />
    <result column="name" jdbcType="VARCHAR" property="name" />
</resultMap>
<select id="getResultBySQL1" statementType="CALLABLE">
{call get_result_by_sql(
#{sql,jdbcType=VARCHAR,mode=IN},
#{result,mode=OUT,jdbcType=CURSOR,javaType=ResultSet,resultMap=getResultBySQLMap},
#{msg,mode=OUT,jdbcType=VARCHAR,javaType=String})}
</select>

<select id="getResultBySQL2" statementType="CALLABLE">
{call get_result_by_sql(
#{sql,jdbcType=VARCHAR,mode=IN},
#{result,mode=OUT,jdbcType=CURSOR,javaType=ResultSet,resultType=java.util.LinkedHashMap},
#{msg,mode=OUT,jdbcType=VARCHAR,javaType=String})}
</select>

Java调用:

public List getResultBySQL(String sql){
        Map<String,Object> map=new HashMap<String, Object>();
        map.put("sql", sql);
        //
        testDao.getResultBySQL1(map);
        System.err.println("1====="+map.get("msg"));
        List list1 = (List)map.get("result");
        //或者
        testDao.getResultBySQL2(map);
        System.err.println("2====="+map.get("msg"));
        List list2 = (List)map.get("result");;
        return list1;
}
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页