This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Needs ur help - - Urgent ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Needs ur help - - Urgent !" Watch "Needs ur help - - Urgent !" New topic
Author

Needs ur help - - Urgent !

saravana kumar
Ranch Hand

Joined: Jun 25, 2002
Posts: 72
Dear friends,
i am developing a website.
i have one jsp page called display.jsp which is displaying records for multiple pages.

every page i set the number of record display is 20.
i am retriving data from java bean calling from display.jsp .
i have done in java bean as retriving data from database and have kept in one jave collection object Vector.
database can have million records.is it efficient to move all data to Vector?
if not so, how to retrive data from database first time 20 records starts from 0 to 20, next 20 records starts from 21 to 40 like that?
please any one give solution for this?
regards
saran
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Paging ResultSets has been covered multiple times and I recommend a search of this forum as well as the JSP and JDBC forums.
If you have the possibility of returning so many rows, it probably isn't a good idea to return them all and store them in a Vector. It won't take long to run out of memory and is even worst if the bulk of the data is never used (ie if 90% of the people only look at the first 2 pages anyway)
Firstly you should look at setting an upper limit on the rows returned, like 100 or 200, maybe even 500. You may find that in your case it is better to include the paging functionality in the SQL so that the DB only returns the exact data you are currently interested. Code ion doing this can be found here
Another possibility is to do a 'light search' first. Do a search that returns all of the rows, but only includes the primary key. This will be much lighter and then you can pull the IDs from this list to load only the specific data you need.
Regardless of what some may say, there is no single silver bullet for ResultSet paging. Have a look at the options available and use the one that fits your problem.
Hope this helps.
Dave
Paul Done
Greenhorn

Joined: Jan 03, 2003
Posts: 22
Also take a look at the Value List Handler pattern from Sun's J2EE Core Design Patterns. This can be used together with the Primary Key query approach to enable lazy loading of pages of data, with forward, back buttons, etc.. I would minimise the usage of a ResultSet and never hold onto it longer that the initial JDBC queries.
Paul
[ January 09, 2003: Message edited by: Paul Done ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Needs ur help - - Urgent !
 
Similar Threads
data in table format in jsp from servlet
Passing Object from one page to another
(How do i do paging in JSP ????? HELP ME >URGENT
Pagination in Java
Related to Javascripet SELECT object