Scrolling result set

Source: Internet
Author: User

Scrolling result set
A scrollable result set means that when reading records in the database, we do not need to read the records one by one. Instead, we can skip several records based on our specific needs before reading the results.

The two attributes in the ResultSet to be used: TYPE_SCROLL_INSENSITIVE (insensitive to scrolling ). Among them, scroll translation is rolling, sensitive translation is sensitive, and insensitive translation is not sensitive. Another attribute: CONCUR_READ_ONLY (read-only for concurrent access ). The concur translation takes place at the same time, that is, concurrency. That is, when the result set is accessed concurrently, only read-only access is allowed, that is, the content in the result set can only be read and cannot be changed!

The preceding two parameters are used when the Statement is created,
Statement stmt = conn. createStatement (ResultSet. TYPE_SCROLL_INSENSITIVE, ResultSet. CONCUR_READ_ONLY );
In this way, after creating a result set (ResultSet) to reference rs, you can use some methods of the result set to make the cursor scroll freely.
The Code is as follows:
Class. forName ("oracle. jdbc. driver. OracleDriver ");
Conn = DriverManager. getConnection (
"Jdbc: oracle: thin: @ localhost: 1521: oracle12c", "c # scott ",
"Tiger ");
Statement stmt = conn. createStatement (ResultSet. TYPE_SCROLL_SENSITIVE,
ResultSet. CONCUR_READ_ONLY );
ResultSet rs1_stmt.exe cuteQuery ("select * from test ");
Rs. next ();
System. out. println (rs. getString (1 ));
System. out. println (rs. isLast ());
System. out. println (rs. isAfterLast ());
System. out. println (rs. getRow ());
Rs. previous ();
System. out. println (rs. getString (1 ));
Rs. absolute (2 );
System. out. println (rs. getString (1 ));

Rs. last () // point the cursor to the last row of records

Rs. isLast () // determines whether to point to the last record

Rs. isAfterLast () // determines whether to point to the top row of the record in the row at the top, that is, the last row

Rs. getRow () // returns the row to which the current cursor points

Rs. previous () // point the cursor to the previous row of the current row

Rs. absolute (int x) // direct the cursor to row x



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.