Solution to paging display problems (jsp, sqlserver, mysql, oracle)

Source: Internet
Author: User


Please refer to this post address and Author: encounter with Mozart (bobrow)
When I encountered this problem when I was working on jsp to implement an online transaction platform, I think this problem must be representative, because the paging display technology is actually used in many places. In order to reduce the time spent by beginners in this area, I summarized the paging display method based on some materials.
Method 1:
The most common method is to obtain the result set of all rows in the database directly, and then use next () by locating the mark ().
Sample Code (mysql for databases ):
// Variable Declaration
Connection sqlCon; // database Connection object
Statement sqlStmt;
ResultSet sqlRst; // result set object
String strCon; // database connection String
String strSQL; // SQL statement
Int intPageSize; // number of records displayed on one page
Int intRowCount; // The total number of records.
Int intPageCount; // the total number of pages.
Int intPage; // the page number to be displayed.
Int I;
/**
* Obtain the total number of records
**/
Class. forName ("com. mysql. jdbc. Driver"). newInstance ();
StrCon = "jdbc: mysql: // localhost: 3306/test ";
SqlCon = java. SQL. DriverManager. getConnection (strCon, "root", "1 ");
SqlStmt = sqlCon. createStatement ();
StrSQL = "select count (*) from message ";
SqlRst = sqlStmt.exe cuteQuery (strSQL); // execute the SQL statement and obtain the result set
SqlRst. next (); // when the record set is opened, the pointer is located before the first record.
IntRowCount = sqlRst. getInt (1); // obtain the total number of data records
SqlRst. close (); // close the result set.
/**
* Total number of pages
**/
IntPageCount = (intRowCount + intPageSize-1)/intPageSize;
/**
* Obtain the result set.
**/
StrSQL = "select time, mail, content from message order by time DESC ";

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.