Talking about Java paging technology

Source: Internet
Author: User

If we want to implement the Java paging technology, we need to define four variables first, they are:

int pagesize;//How many records are displayed per page

int pagenow;//Hope Reality first few pages

int pagecount;//How many pages there are altogether

int rowcount;//How many records are there altogether?

Description

1.pageSize is the specified

2.pageNow is the user's choice

3.rowCount is the query from the table

The 4.pageCount is calculated, and the calculation is:

if (rowcount%pagesize==0)

{

Pagecount=rowcount/pagesize;

}

Else

{

pagecount=rowcount/pagesize+1;

}

The above note may listen to a little foggy, I would like to give an example to specify:

There are user tables, a total of 9 records, namely: rowCount; Each page shows 3 records, namely: pagesize=3; then according to our algorithm: pagecount=3, just not much more, if each page shows four records, Pagesize=4, then pagecount= 3, the last page will only have 1 records, so it is correct anyway.

In response to the previous question, it is easy to think of the use of the Select field list from the table name where ID between? and?

We use a users table as an example to show the third page, the query statement is: SELECT * from the users userId between 7 and 9;

This SQL statement is really fast, but it has a problem, that is, if the ID of the table is deleted, then a page may be missing a record. Experiment with SQL Server's Query Analyzer, so our final solution is the following statement:

Select top pageSize field list from table name where ID not in (select Top pagesize* (pageNow-1) ID from table name);

Talking about Java paging technology

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.