Java EE JDBC resultset internal and external movement

Source: Internet
Author: User

ResultSet inside and outside movement

@author Ixenos

Movement of the cursor within and outside the moving finger

Inside movement is a resultset to get the cursor after that!

Outer movement is the iteration of multiple resultset

Inside move

A generic database does not allow a single query to submit multiple SELECT statements.

1.execute executes the SQL statement and returns a result set of resultset,

2. There is a cursor next in front of the first tuple (imagine), call Hasnext will determine the cursor next to a tuple does not exist

3.rs.next Locating rows (tuple triple), Rs.getxxx Locating Columns (field fields)

Move outside

Multiple result sets may be returned in the execution of a stored procedure, or in some operations that allow a single query to submit multiple SELECT statements

1. Execute the SQL statement using the Execute method to get the first result set or update count,

2. Call the Getmoreresults method repeatedly, move the resultsets cursor to the next result set,

3. When there are no more result sets or update counts, complete the operation

4.stat.getresultset locates the current result set, stat.getupdatestatement the update count, Stat.getmoreresults locates the next result set

Boolean isresult = Stat.execute (sql); Boolean done = False;while (!done) {      if (isresult) {           ResultSet result = Stat.getresultset ();      }else{           int updatecount = Stat.getupdatecount ();           Isresult is false, but count! =-1, stating that there is a SQL operation but does not return a result set           if (updatecount >= 0) {                 ...           }else{                 //count is-1, the description getmoreresults has no result set, and there is no other SQL operation, at which time quit done                 = true;}      }      if (!done)  Isresult = Stat.getmoreresults ();}

  

Java EE JDBC resultset internal and external movement

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.