• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Displaying few rows on each page

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm creating a query which can get many rows in the resultset,depending on what the user enters as parameters for the query.I want to display only few rows per jsp page,and have a NEXT button which will display the specified number of rows per page. I also want to be able to allow the user to choose the number of rows they want to see in each page.How can I do this ?
Can I specify in the query itself the number of rows I want ?
Any help will be greatly appreciated.
Thanks.
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I can think of one way to do this.
Let's have a bean that has two attributes. One attribute is the max# of rows per page, the other attribute is the result set.
*this is just a sketch and not intended to be run as is.

Now let's see some of the code the jsp might use to implement this bean. Assume you are using a bean called rowBean in session scope, and that you have already set it's result set.
(btw, all my jsp books are at work and I may be off on some of my syntax)

Hope this helps.
 
Mallika Kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jason,
The way I'm showing the resultset is by storing it in a vector and displaying the vector onto the jsp page. So I want to know if I can show the results from the vector itself. We're closing the resultsets once the method in java class is executed, so passing resultset is not an option.
I want to show selected number of rows per page, without adding the result object(vector) to the session. Is there a way to do this ?
Thanks.
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's do it this way then. But first, unless there was some reason you absolutely didn't want to, you could use the original code as written but close the result set in the isMore() method if rs.isAfterLast(), right after where you set more = false. This way should actually be a bit more efficient since it saves the overhead of iterating through the ResultSet and placing it into the vector.

Anything you need to do to get your Strings or whatever out of obj could be done in the getNextRow() method. The jsp code should work as written except change the call to isMore() to hasNext(). I'm sure this could be written many different, probably better, ways but this should do what you need.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic