Sample Code for correct paging display in MySQL database

Source: Internet
Author: User

The following articles mainly describe the actual application code correctly displayed by page in the MySQL database, as shown below, the following is a description of the actual application code correctly displayed by page in the MySQL database. I hope it will be helpful for you in your future studies.

 
 
  1. public List<Product> getProducts(int pageNo, int pageSize)  
  2. {  
  3. Connection conn=null;  
  4. ResultSet rs=null;  
  5. List<Product> list=new ArrayList<Product>();  
  6. conn=DB.getConn();  
  7. String sql="select * from product limit "+(pageNo-1)*pageSize+","+pageSize;  
  8.  
  9. rs=DB.executeQuery(conn, sql);  
  10. try  
  11. {  
  12. while(rs.next())  
  13. {  
  14. Product p=new Product();  
  15. p.setId(rs.getInt("id"));  
  16. p.setName(rs.getString("name"));  
  17. p.setDescr(rs.getString("descr"));  
  18. p.setNormalPrice(rs.getDouble("normalprice"));  
  19. p.setMemberPrice(rs.getDouble("memberprice"));  
  20. p.setCategoryId(rs.getInt("categoryid"));  
  21. p.setPdate(rs.getTimestamp("pdate"));  
  22. list.add(p);  
  23. }  
  24. } catch (SQLException e)  
  25. {  
  26. e.printStackTrace();  
  27. }  
  28. finally  
  29. {  
  30. DB.closeRs(rs);  
  31. DB.closeConn(conn);  
  32. }  
  33. return list;  

The above content describes the code that is displayed by page in the MySQL database. I hope it will help you in this regard.

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.