JSP: the Rs. Last () method is not available. Learn the resultset cursor notes.

Source: Internet
Author: User
Tags rowcount custom cursors

Cause:
Today, I want to develop a program to flip the page of the article list. I need to obtain the total number of data rows in the dataset.
The method used is as follows:
--------------------------------------------------
Int rowcount = 0;
Rs. Last ();
Rowcount = Rs. getrow ();// Move to the end to retrieve the number of the current row and obtain the total number of rows.
Out. Print ("Total number of rows:" + rowcount + "<br/> ");
// Out. Print ("islast:" + Rs. islast () + "<br/> ");
// Out. Print ("isafterlast:" + Rs. isafterlast () + "<br/> ");
Rs. beforefirst (); // easy to output data later
---------------------------------------------------
This method is not supported when Rs. Last () is executed!
[Microsoft] [sqlserver 2000 driver for JDBC] unsupported method: resultset. Last

Data analysis:
==================================Cursor read-only forward======================================
Java. SQL
Interface: Connection
Method:Createstatement
Statement createstatement ()
Throws sqlexception
Create a statement object to send SQL statements to the database.
SQL statements without parameters are usually executed using statement objects.
If you execute the same SQL statement multiple times, the preparedstatement object may be more effective.
The result set created using the returned statement object is of the type_forward_only type by default,
And has the concur_read_only concurrency level. [--- Note that the cursor is read-only forward by default]

Return Value:
A new default statement object
Throw:
Sqlexception-if a database access error occurs

======================================Custom cursors==============================================
Java. SQL
Interface: Connection
Method: createstatement
Statement createstatement (INT resultsettype,
Int resultsetconcurrency)
Throws sqlexception
Create a statement object that will generate

The resultset object of the given type and concurrency. This method is the same as the createstatement method, but it allows rewriting.

The default result set type and concurrency.

Parameters:
Resultsettype-result set type, which is
--- Resultset. type_forward_only, // forward cursor
--- Resultset. type_scroll_insensitive or // This constant indicates the RS type that can be rolled but is generally not affected by other changes
--- One of resultset. type_scroll_sensitive // Constant indicates the RS type that can be rolled and is usually affected by other changes.

Resultsetconcurrency-concurrency type; it is
--- Resultset. concur_read_only or // read-only
--- Resultset. concur_updatable // you can modify it.
Return Value:
A new statement object that generates a resultset object with a given type and concurrency
Throw:
Sqlexception-if a database access error occurs, or the given parameter is not a resultset constant indicating the type and concurrency
Start with the following versions:
1.2

Solution:

Specify the cursor parameter when creating a statement object
Conn = drivermanager. getconnection (getconnectionurl (), dbusername, dbpassword );
Stmt = conn. createstatement (resultset. type_scroll_sensitive, resultset. concur_updatable );

 

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.