Efficient jsp paging Query

Source: Internet
Author: User

Jsp is as follows:
**********************
<% @ Page language = "java" import = "java. util. *, java. SQL. *" %>
<% @ Page contentType = "text/html; charset = gb2312" %>
<Jsp: useBean id = "cn" scope = "page" class = "myConnection. Conn"/> <! -- Reference the bean for database operations and complete it by yourself. I will not go into details here -->
<%
Int curpage = 1; // current page
Int page_record = 20; // number of records displayed on each page
// Use the following method (SQL query is completed, and the speed is fast)
Curpage = Integer. parseInt (request. getParameter ("page"); // obtain the passed value, the page to be displayed
ResultSet rs = cn. rsexecuteQuery ("select top" + page_record + "* from tablename where id not in (select top" + (curpage * page_record) + "id from tablename order by id desc) order by id desc ");
// This query statement returns the 20 records on the 1000 page to be displayed. The general idea is that subqueries exclude all records before the records to be displayed, the parent query sorts the remaining records in descending order.
While (rs. next ){
Out. println (rs. getInt ("id"). toString ());
}
Rs. close ();
%>

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.