Ibatis calls the Stored Procedure processing method that returns two cursors

Source: Internet
Author: User

If you encounter such a problem, you need to call a stored procedure that returns two cursors through ibatis. I found many questions on the Internet, but it was difficult to find a solution. So I estimated that the method of processing the stored procedure that returned a cursor was called, the stored procedure that calls two returned cursors. Share it with you.


Stored Procedure:

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 statement: <! -- Cursor 1 Data configuration --> <resultmap class = "com. Table1" id = "result1">
<Result property = "data1" column = "data_1"/>
<Result property = "data2" column = "data_2"/>
<Result property = "data3" column = "data_3"/>
<! -- Cursor 2 Data configuration -->
<Resultmap class = "com. Table2" id = "result2">
<Result property = "data4" column = "data_4"/>
<Result property = "data5" column = "data_5"/>
<Result property = "data6" column = "data_6"/>
<! -- Call the input parameter configuration of the stored procedure -->
<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"/>
<! -- Start the stored procedure -->
<Procedure id = "testid" parametermap = "testparam">
<! [CDATA [
{? = Call fn_tester (?,?)}

Data acquisition at the DaO layer: Table1 and Table2 are two pojo;

Public VoidGetdata (MapParammap)Throws Sqlexception{Try{Getsqlmapclienttemplate (). queryforobject (Namespace+ "Testid", parammap); // cursor 1 gets the list <Table1> Datalist1 =(List <Table1>) parammap. Get ( "Table1data" ); // Cursor 2 get list <Table 2> Datalist2 =(List <Table2>) parammap. Get ( "Table2data" );}Catch(SqlexceptionE)
{ThrowE;} system.Out. Println (Datalist1); System.Out. Println (Datalist2);}

Write a test case and you can test it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.