iBatis調用返回兩個遊標的預存程序處理方法

來源:互聯網
上載者:User

遇到這麼一個問題,需要通過Ibatis調用一個返回兩個遊標的預存程序。在網上找資料來著,發現問此問題的挺多的,但難以找到解決方案,於是,估摸著調用返回一個遊標的預存程序處理方式,整出了調用返回兩個遊標的預存程序。現貼出來與大家共用。

舉例如下:

預存程序:

create or replace function fn_tester(       cursor_data1  out sys_refcursor ,       cursor_data2
 out sys_refcursor )return numberas  
begin  begin      open cursor_data1
     for SELECT          e.data_1,          e.data_2,          e.data_3   from a_table
e;       open cursor_data2
 for    for SELECT          e.data_4,          e.data_5,          e.data_6   from b_table
e;   end fn_tester;
sqlmap 寫法如下:<!-- 遊標1資料配置--><resultMap class="com.table1" id="result1">
<result property="data1" column="data_1"/>
<result property="data2" column="data_2"/>
<result property="data3" column="data_3"/>
</resultMap>
<!-- 遊標2資料配置-->
<resultMap class="com.table2" id="result2">
<result property="data4" column="data_4"/>
<result property="data5" column="data_5"/>
<result property="data6" column="data_6"/>
</resultMap>
<!-- 調用預存程序傳入參數配置-->
<parameterMap class="java.util.HashMap" id="testParam">
<parameter property="result" jdbcType="INTEGER"
             javaType="java.lang.Long" mode="OUT" />
<parameter property="table1Data" jdbcType="ORACLECURSOR"
             javaType="java.sql.ResultSet" resultMap="result1" mode="OUT" /> 
         <parameter property="table2Data" jdbcType="ORACLECURSOR"
             javaType="java.sql.ResultSet" resultMap="result2" mode="OUT" />
</parameterMap>
<!-- 預存程序調起-->
<procedure id="testId" parameterMap="testParam">
<![CDATA[  
{? = call fn_tester(?,?)}
]]>
</procedure>  


dao層資料擷取:其中table1、table2是兩個pojo;

      public void getData(Map paramMap) throws SqlException {             try {                  getSqlMapClientTemplate().queryForObject( NAMESPACE + "testId" ,paramMap);                   // 遊標1擷取                  List< table1> dataList1= (List<table1>)paramMap.get( "table1Data" );                   // 遊標2擷取                  List< table2> dataList2= (List<table2>)paramMap.get( "table2Data" );                  } catch (SqlException e)
{                  throw e;            }                  System. out .println(dataList1);            System. out .println(dataList2);      }

自己寫個測試案例就可以測試了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.