Avatar of ubsjmg
ubsjmg

asked on 

Paging Through Results on the Web

I need to create a servlet that accesses a database and displays 10 rows at a time.  Can someone provide me with an example (without using the session object) of providing this capability with JDBC 2.0. in a servlet. If using the session object is the preferred method of paging and maintaining state please let me know.  I want to avoid the session object due to performance and scalability issues.  Thanks
Java

Avatar of undefined
Last Comment
ubsjmg
Avatar of sarat_atluri
sarat_atluri

Hi
One way to achieve it is through using a hidden form field(In case of using html to display results) and using a query like the one i had written below.
 
 This query will give you records and count of that record.i.e..like if accNo is the primary key and it's value is 20 and it is the 13th record in the table(It became 13th record because the some of records whose accNo<20 might be deleted.), the query gives this record details and number 13 indicating it is the 13th record.
 The value of the the hidden form feild will be this record count number.First it will be 0.When we submit the request, using the query, we retrive records whose record count>0 and <(0+10).Now we set the hidden variable's value to 10.Again when we submit the form, we retrive recordcount>10 and <(10+10) and set hidden value to 20 and proceed like this .
 The query is like following
 select *,(select count(*) from dr_accs where dr_accs.accno=d.accno) as recNum
 from dr_accs d
 where recNum>0 and recNum<(0+10)
 orderby recNum

This is the case when u access the servlet for first time.Instead of the 0, u put the hidden varible's value.



Avatar of gilap
gilap

try this:
accept the result from DB once, and store it in a Vector.
call your servlet with a 'startFrom' parameter. on each re-call of the servlet, just iterate the Vector and display the items from startFrom to startFrom+10.

this will save you multiple access to the DB.
Avatar of ubsjmg
ubsjmg

ASKER

qilap,

I am fairly new to servlet programming.  Would I have to store the vector in a session object to keep state between servlet requests?  

ASKER CERTIFIED SOLUTION
Avatar of gilap
gilap

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of ubsjmg
ubsjmg

ASKER

Comment accepted as answer
Avatar of ubsjmg
ubsjmg

ASKER

Thanks for your help...
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo