Database Connection Pool

Source: Internet
Author: User
Calculate and determine the total number of pages of the data table: 101pageSize1001010. Rowsselectcount (1) fromusers; Method 1: pageCountrowspageSize + (rows % pageSize0? ); Method 2: pageCount (rows + (pageSize-1) (pageSize); publicvoiddoGet (HttpServletRequestreq,

The calculation determines the total number of pages of the data table: 101/pageSize = 100/10 = 10. Rows = select count (1) from users; Method 1: pageCount = rows/pageSize + (rows % pageSize = 0? ); Method 2: pageCount = (rows + (pageSize-1)/(pageSize); public void doGet (HttpServletRequest req,

The calculation determines the total number of pages of the data table: 101/pageSize = 100/10 = 10. Rows = select count (1) from users; Method 1: pageCount = rows/pageSize + (rows % pageSize = 0? 0: 1); Method 2: pageCount = (rows + (pageSize-1)/(pageSize); public void doGet (HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException {// Step 1: define the number of rows displayed per page int pageSize = 10; try {// Step 2: Get the number of rows in the data table QueryRunner run = new QueryRunner (performanceutils. getDatasSource (); String SQL = "select count (*) from users"; Object o = run. query (SQL, new ScalarHandler (); int rows = Integer. parseInt (o . ToString (); // Step 3: calculate the total number of pages divided into int pageCount = rows/pageSize + (rows % pageSize = 0? ); // Place the number of pages in reqreq. setAttribute ("pageCount", pageCount);} catch (Exception e) {e. printStackTrace ();} // forward to req. getRequestDispatcher ("/jsps/show. jsp "). forward (req, response );}
Step 4: analyze the start position of limit

User requested facial code

Start

Algorithm:

1

Limit 0, pageSize

Start

= (CurrentPage-1) * pageSize

2

Limit 10, pageSize

3

Limit 20, pageSize

Step 5: page after page

Each page can display up to 10 page numbers.

PageNum = 10;

StartNo

EndNo

Current page number

Page number range

Algorithm

1

1 ~ 10

If (currentPage <= pageNum/2)

1 ~ 10

2

3

4

5

6

2 ~ 11

6-4 = 2 =

6-(pageNum/2-1) = 2 = startNo

EndNo = startNo + (pageNum-1) = 11

7

3 ~ 12

8

4 ~ 13

9

10

11

11-4 = 7

EndNo = 7 + 9 = 16

EndNo = 11;

StartNo = 2 = endNo-(pageNum-1 );

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.