Implementation of DB2 Paging

Source: Internet
Author: User

The following describes the DB2 paging script for your reference. If you are interested in DB2 paging, you may wish to take a look at it. I believe it will inspire you to learn about DB2 paging.

 
 
  1. String sqlcount = "select count (*) from stu. book" + condition;
  2. System. out. println (sqlcount );
  3. Int curPage; // the page number to be displayed.
  4. Int totalPages; // the total number of pages.
  5. Int pageRecord = 10; // number of records to be displayed on each page
  6. Int totalRecords; // The total number of records that meet the condition
  7. If (CPage! = Null ){
  8. CurPage = Integer. parseInt (CPage );
  9. If (curPage <1 ){
  10. CurPage = 1;
  11. }
  12. } Else {
  13. CurPage = 1;
  14. }
  15. Connection con = Dao. getConn (); // obtain the database Connection
  16. Try {
  17. Ps = con. prepareStatement (sqlcount );
  18. Rsw.ps.exe cuteQuery ();
  19. If (rs. next ()){
  20. TotalRecords = rs. getInt (1 );
  21. If (totalRecords % pageRecord = 0)
  22. TotalPages = totalRecords/pageRecord; // when the number of records displayed on each page can be divisible by the total number of records, the total number of pages is the total number of records divided by the number of records displayed on each page
  23. Else
  24. TotalPages = totalRecords/pageRecord + 1; // when the number of records displayed on each page cannot be divisible by the total number of records, the total number of pages is the total number of records divided by the number of records displayed on each page plus 1
  25. String SQL;
  26. If (curPage = 1 ){
  27. SQL = "select * from stu. book" + condition + "FETCH FIRST" + pageRecord + "ROWS ONLY ";
  28. } Else {
  29. SQL = "select * from stu. book "+ condition +" and booknum not in (select booknum from stu. book "+ condition +" fetch first "+ (curPage-1) * pageRecord +" rows only) "+" fetch first "+ pageRecord +" rows only ";
  30. }
  31. System. out. println (SQL );
  32. Ps = con. prepareStatement (SQL );
  33. Rsw.ps.exe cuteQuery ();
  34. While (rs. next ()){
  35. Book B = new Book ();
  36. B. setBooknum (rs. getString (1 ));
  37. B. setBookname (rs. getString (2 ));
  38. B. setBookindate (rs. getString (3 ));
  39. B. setBorrower (rs. getString (4 ));
  40. B. setLenddate (rs. getString (5 ));
  41. B. setRemark (rs. getString (6 ));
  42. Al. add (B );
  43. }
  44. } Else {
  45. Return al;
  46. }
  47. } Catch (SQLException e1 ){
  48. E1.printStackTrace ();
  49. }
  50. Return al;

The above is the implementation of DB2 paging.

DB2 cursor and usage

How to manage DB2 tablespaces

DB2 database Permissions

Silent status of three DB2 tables

Troubleshooting of DB2 database detachment

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.