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配置:

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" />



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;
}

你可能感兴趣的:(我的技术文档)