Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

logic to display certain number of records in JSP

 
Neha Sharma
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody suggest me on the logic how to build a jsp in which I need to display 10 records from the resutlset on each. At the bottom of the page I have to display href values page 1 of 7 , 2 of 7 and so on. When the user clicks on any of them I have to show the data. I not able to think of a logic how can I achieve that.
Thanks
Neha
 
Jeff Sunder
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can put your results in a vector, then loop through your vector to display the results.
 
Dave Soto
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing to be careful of when storing results (presumably in the session) of a query is that you have to make sure your database isn't too large. What if a search returned 50,000 rows? You don't want to save a 50,000 row vector into a session. All you need is a handful of users to nail you with some searches like that and you are looking at some big memory consumption on your app server.

That's what EJB is for, but that's a whole different discussion.
 
Sid Scud
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Neha,
I have implemented the same thing. You can go for CachedRowsets than going for ResultSets. Going thru CachedRowset is easier and it provides many methods which are very useful.
C if itt works on your side too... atleast it gave me good and fast results.
-Sid
 
Kareem Gad
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Siddarth,
I tried to find where in the Java API is this CachedRowSet class ?
Can you please clear this out ?

------------------
KaReEm
 
Kareem Gad
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How i would usually go about something like this and i've done it before is to pass boundary parameters to the page the will show the results, so by default these parameters would be 0, 20 let's say if u want to show 20 records.
and then if i will provide a next link at the end of the 20 rows i pass the next set of boundary parameters 20, 40 and so on
it really depends on how your database manages it , for mySQL you give a limit [start_row],[number_of_rows] format
for oracle you give a condition something like
where rownum < 20 something like that.

------------------
KaReEm
 
Sid Scud
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kareem,
Here is the link where u get the specs and the jar file.
http://developer.java.sun.com/developer/earlyAccess/crs/
(u need to be a JDC member)
Hope it helps u.
-Sid
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic