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 ";