• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to implement Pagination

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am new to the pagination concept. I want to implement pagination in my website just like the one implemented in Yahoo mail serviece. I want ot display 20 records at a time and navigates through the pages with the help of NEXT and PREVIOUS links. Now let me tell you I have searches all the relevant forum and did not get any wanted code. Can any body give the code for it.'
NB : I don't wnat to use JSP Taglib or JSLT or java scrip or any additional thing. With the help of simple jdbc and any logical code i want to do the same in the JSP or Servlet. Please help me out.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can search the same or JDBC forum with the word "pagination". You'll get many threads discussing same.

Thanks.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is also an entry in the JSP FAQ for this question.
http://faq.javaranch.com/view?PaginationOrPaging
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try Pager Taglib.Its very easy and simple too.

The respective url is http://jsptags.com/tags/navigation/pager/pager-taglib-2.0.html#item
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
am doing the same thing in which i am calling the database to send me the next 20 records by sending some parameters (like timestamp, serial no and a flag that says what button has been pressed) in the last record for the "Next" button and some parameters in the first record for the "Previous" button.

These parameters form a part of the Stored procedure call from my servelet.
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This solution is through Java

you can make use of the
Methods provided by the ResultSet

I am Sending you the code for pagination



ResultSet rs=null;
boolean isPageSelected = false;
int lb = 0 , ub = 0 ,pg = 0,totalrecords=0,recordsPerPage=10;
// variables used in paging

String selected_page= request.getParameter("page");
if(selected_page == null || selected_page == "" || selected_page.equals("") )
{// page not selected
isPageSelected = false;
selected_page="";
lb = 0;
ub =recordsPerPage;
}
else
{// page is selected
isPageSelected = true;
pg = Integer.valueOf(selected_page).intValue();
lb = recordsPerPage*(pg-1);
ub = lb + recordsPerPage;
}

query="select * from temp";

rs=st.executeQuery(query);
rs.last(); // Jump to last row
totalrecords = rs.getRow(); // get the row count
rs.beforeFirst();
// reset to allow forward cursor processing

int noofpages=0;
if(totalrecords%recordsPerPage==0)
noofpages = totalrecords/recordsPerPage;
else
noofpages = totalrecords/recordsPerPage +1;

int cnt = lb;
rs.absolute(lb+1); // move to record

do{
// get the details what ever you want
cnt++;
}while(rs.next()& (cnt<=ub))
 
reply
    Bookmark Topic Watch Topic
  • New Topic