Stored procedures often need to return multiple result sets.
Mysql
Directly Using
Select
Returns the result set. While
Oracle
You need to use a cursor to return the knot.
Result
Set. This point
Mysql
The following code outputs two result sets:
SQL
Code 2-1:
Create procedure test_proc_multi_select () <br/> BEGIN <br/> select * from testproc; <br/> select * from testproc where id = 1; <br/> END;
Java
Use loops to obtain the result set data:
Java
Code 2-1:
Con = mconnection. getconn (); <br/> string SQL = "{call test_proc_multi_select ()}"; <br/> cs = con. preparecall (SQL); <br/> Boolean hadresults = cs.exe cute (); <br/> int I = 0; <br/> while (hadresults) {<br/> system. out. println ("Result No: ----" + (++ I); <br/> resultset rs = cs. getresultset (); <br/> while (RS! = NULL & RS. next () {<br/> int id1 = Rs. getint (1); <br/> string name1 = Rs. getstring (2); <br/> system. out. println (id1 + ":" + name1); <br/>}< br/> hadresults = cs. getmoreresults (); // check whether more result sets exist <br/>}