Paging notice knowledge points:
(1) rolling result set of jdbc2.0.
(2) http get request.
I. scrollable result set
Connection con = drivermanager. getconnection ();
Preparedstatement stmt = con. preparestatement (SQL, resultset. type_forward_only, resultset. concur_read_only );
Resultset rs = stmt.exe cutequery ();
Common Methods:
(1) Rs. Absolute (n); you can jump the pointer to row n.
(2) Rs. Relative (n); you can move the pointer down or up n rows.
(3) Rs. First ();
(4) Rs. Last ();
(5) int currow = Rs. getrow (); the current row to which the Pointer Points
Ii. function implementation decomposition 1. Number of computing results
Rs. Last ();
Int size = Rs. getrow ();
The number of results.
2. Several pages are required.
If five records can be stored on one page
Int pagecount = (size % 5 = 0 )? (Size/5): (size/5 + 1 );
You can obtain several pages.
3. Control the number of records displayed on the page
If five records can be displayed on one page, count by count.
Int COUNT = 0;
Do {
If (count> = 5) break;
.....
Count ++;
} While (Rs. Next ());
Through the break statement, it can be displayed to jump out when the specified entry is exceeded.
4. How to know the page number
Use http get to indicate the current address in the address bar, such as http ://.......? Curpage = 1 indicates the first page.
String TMP = request. getparameter ("curpage ");
If (TMP = NULL ){
TMP = "1 ";
}
Curpage = integer. parseint (TMP );
You can get the current page.
Note:
Rs. Absolute (1); indicates pointing to the first record;
Rs. Absolute (0 );
Rs. Absolute (curPage-1) * pagesize + 1); adjust the result set pointer to the beginning of the record that should be displayed on the current page.
For example, if five records are displayed on one page and the current page is the second page, you need to adjust the pointer to 6. If the current page is the third page, you need to adjust the pointer to 11.
5. Click the homepage, Previous Page, next page, and last page.
<A href = "multipage. jsp? Curpage = <% curpage + 1%> "> next page </a>
<A href = "multipage. jsp? Curpage = <% curPage-1 %> "> previous page </a>
<A href = "multipage. jsp? Curpage = <% pagecount %> "> last page </a>
<A href = "multipage. jsp? Curpage = 1 "> homepage </a>
6. To save the current page location, you need to set the current page location as a global variable. Comprehensive code:
<% @ Page contenttype = "text/html" pageencoding = "gb2312" Language = "Java" %> <% @ page import = "Java. SQL. * "%> <HTML>