MySQL Stored Procedure (II) -- Multi-result set return and Java acquisition

Source: Internet
Author: User

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

 

 

Related Article

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.