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.
- String sqlcount = "select count (*) from stu. book" + condition;
- System. out. println (sqlcount );
- Int curPage; // the page number to be displayed.
- Int totalPages; // the total number of pages.
- Int pageRecord = 10; // number of records to be displayed on each page
- Int totalRecords; // The total number of records that meet the condition
- If (CPage! = Null ){
- CurPage = Integer. parseInt (CPage );
- If (curPage <1 ){
- CurPage = 1;
- }
- } Else {
- CurPage = 1;
- }
- Connection con = Dao. getConn (); // obtain the database Connection
- Try {
- Ps = con. prepareStatement (sqlcount );
- Rsw.ps.exe cuteQuery ();
- If (rs. next ()){
- TotalRecords = rs. getInt (1 );
- If (totalRecords % pageRecord = 0)
- 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
- Else
- 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
- String SQL;
- If (curPage = 1 ){
- SQL = "select * from stu. book" + condition + "FETCH FIRST" + pageRecord + "ROWS ONLY ";
- } Else {
- 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 ";
- }
- System. out. println (SQL );
- Ps = con. prepareStatement (SQL );
- Rsw.ps.exe cuteQuery ();
- While (rs. next ()){
- Book B = new Book ();
- B. setBooknum (rs. getString (1 ));
- B. setBookname (rs. getString (2 ));
- B. setBookindate (rs. getString (3 ));
- B. setBorrower (rs. getString (4 ));
- B. setLenddate (rs. getString (5 ));
- B. setRemark (rs. getString (6 ));
- Al. add (B );
- }
- } Else {
- Return al;
- }
- } Catch (SQLException e1 ){
- E1.printStackTrace ();
- }
- 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