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

Displaying few rows on each page

 
Mallika Kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • 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.
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic