• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to do paging for large resultset?  RSS feed

 
Zoe Zhao
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Beginner seeking advice... I'm developing a website using Struts. My pages are writtenin JSP and supported by form and action beans. My database query returns 10,000 records, and I need to display 30 records for each page, and have "next" and "previous" button to help navigate. Does anybody have sample code to do paging in JSP/JavaBeans within Struts? Thanks a lot in advance!

Zoe
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has been discussed many times before so please perform a search on this and the JDBC forum for the previous discussions.

Essentially it boils down to this: don't return 10,000 records. Make the database do the work for you and only return the slice of the result set that you intend to display.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have on occasion for slow queries done a hybrid of the approach bear mentions where I have the query return a limited batch of rows (say 500), and keep this in memory and the user pages through this until they get to the end and then i issue the query again for the next 500 rows. I only did this in this case as returning a page (say 25 rows) was just as expensive as returning 500. In general, if possible I prefer Bears approach.

All this of course should be monitored and you should only use the approach I mentioned if you KNOW if will improve performance, and that performance gain is substantial.
 
Poobhathy Kannan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to still use paging..

Check out the pager taglib:
 
Zoe Zhao
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've download the taglib, and tried the demo. looks nice. Try to do pager in my jsp based on their samples, but have problem define <pg:item> -- How do I send my query resultset (either from the action bean or from this jsp itself) into this pager item thing? Anybody have any exmples?

Thank you so much!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!