Reprint please specify the original address:
In the development process, often do one thing, is also the most basic thing, is to query the data from the database, and then displayed on the client. When data is not available, it can be displayed within a single page. However, what if the query records are hundreds of and thousands? Direct a page to show exactly how long the table is ... At this point, we can use the paging technology.
What is paging? As follows:
A total of 100 records were queried, and if a one-time display of the table would be a lot of rows, the user experience is poor. And we use pagination display, a page showing 10 records, total 10 pages. Users can browse by themselves, record less, clear display.
The following is a discussion of the implementation of the paging effect, there are two ways:
First: One query, display in batches.
That is, we can perform a database query operation to get the result set Rs. The current page's record is then displayed by moving the pointer. This allows you to navigate to the first record of the current page with Rs.absolute (the current page number * number of records per page) and then display N records through the while loop (n shows the number of records per page). When jumping pages, just modify the currentpage to change the current page number when relocating to the next page, reposition the record pointer, and display n records through the while traversal.
Reference code:
<%
intIntpagesize = 10;//number of records displayed on a page intIntrowcount;//Total Records intIntpagecount;//Total PagesString strpage;//the page number to be displayed from the form or URL intIntpage;//number to display, integer converted by strpage//position the record pointer on the first record of the page you want to displaySqlrst.absolute ((intPage-1) * intpagesize + 1); //Show Data intI=0; String user_id, user_name, User_sex, User_phone, user_age; while(I < intpagesize &&!)Sqlrst.isafterlast ()) {user_id= sqlrst.getstring (1); User_name= Sqlrst.getstring (2); User_sex= Sqlrst.getstring (3); User_phone= Sqlrst.getstring (4); User_age= Sqlrst.getstring (5); %> <tr> <td><%=user_id%></td> <td><%=user_nam E%></td> <td><%=user_sex%></td> <TD><%=USER_PHONE%>&L t;/td> <td><%=user_age%></td> </tr> <%Sqlrst.next ();//move record pointer to next record I++;//Statistics How many records are displayed on the current page}%>
This method is pseudo-paging, which is a paging effect implemented on the client.
Second: Paging on the service side. Skip to page N to query, display page n content.
Javaweb page display Content--database paging query