How to implement pagination from database level.

Please provide me any sample source code for the same

Showing Answers 1 - 3 of 3 Answers

bachi14

  • Dec 26th, 2007
 

ArrayList resultList = (ArrayList)session.getAttribute("allzones");
int pageNo = a.getPageNumber();// get the pageno form ur class
 
 int recordCount=0;
 if(resultList!=null && resultList.size() > 0)
 {
  recordCount = resultList.size();  
 }
 int maxCount = a.getMaxRecords(); // get the max form ur class
 
 int maxRowsPerPage = 5;// how many records u want to display give the number

int PAGE_NMBERS = 5;// how many page to displayed ie (1 2 3 4 5 ... )
int pageCount = (new Double(Math.ceil((double)maxCount/maxRowsPerPage))).intValue();//maxCount/maxRowsPerPage;
 int startIndex =1;   
    
 int aNum =(pageNo+1)-startIndex;
 
 if(aNum>1)
  startIndex=(pageNo+1)-2;
  
 int endIndex =startIndex+PAGE_NMBERS;
 
 if(endIndex > pageCount)
 {
  endIndex=pageCount+1;
  startIndex=endIndex-PAGE_NMBERS;
 } 
 if(endIndex <=PAGE_NMBERS)
 {
  startIndex=1;
  endIndex=pageCount+1;
  
 }

if(maxCount>0){
Page <%=pageNo+1%> of <%=pageCount%> (<%=maxCount%>


<%  
   for(int i=startIndex;i<endIndex;i++)
   {
    if((pageNo+1)==i)
    {
  %>
     <b><%=i%></b>
  
  <%
    }
    else 
    {
  %>
     <a href="#pgeView" onClick="submitResult('<%=(i-1)%>')"><u><%=i%></u></a>

  <%
    }
   }
  %>

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions