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
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
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 ]