Solved

MVC - Looping through a ResultSet

Posted on 2002-03-29
7
711 Views
Last Modified: 2013-11-24
I am developing a site and learning the MVC approach at the same time.

I currently have a controller that takes a parameter to determine what page the user wants to go to. Using external XML files i store information about what servlet and jsp to load.

Once the destination has been determined, for example 'news', the newsServlet is invoked which calls a DB Query method to extract ( for example ) the latest 10 news items.

This i have working perfectly so far with a ResultSet returned.

What i want to do now is using a bean and its accompanying JSP loop through the ResultSet and display the results. I also want to implement paging into the solution. (display n number of records per page with the ability to move back and forward through the ResultSet ie 10 records at a time ).

As a solution i assume i could save the ResultSet into a session. Is this a good idea, if so how do i go about coding this solution and are there more acceptable methods to do this?

thanking you all in advance,

Damian
0
Comment
Question by:dgeorgio
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 

Accepted Solution

by:
rashidkamranbs earned 200 total points
ID: 6906498
First for moving foward and Backward you need to create a scroll able result set.

Second you can use the same absolute(int) method of result set to generate paging explicitly.

Thrid it wouldn't be a good chioce to place a ResultSet in a session.. cuz the connection will remain open untill the pagin complete..

alternatively you can use XML to cache the results.. n pagig in a XML is not a big deal


0
 

Author Comment

by:dgeorgio
ID: 6910079
Sorry but i am still not sure how i am suppose to go about iterating through the resultSet returned by the servlet using the bean and the JSP. ( I am very new to Java and learning as I go ).

0
 

Expert Comment

by:rashidkamranbs
ID: 6910917
See when you create your statement you need to tell what kinda resultset ya want.. for scrolling in either direction ur createStatement method could be something like

Statement st=cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE );

The above line is one of the approach..
now the suppsoe rs is the ResultSet object return by this statement.. you can move in either direction by calling

rs.absolute(rowNo);
or
rs.next();
or
rs.previous();

Now i dont think if there is ne problem to do paging kinda stuff while there are number of methods with boolean returned type
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dgeorgio
ID: 6911753
Yes, thankyou that all makes sense but I am unsure how i access the information stored in the ResultSet with the use of the bean and the jsp.

This is currently what i have.

I have a servlet that when invoked by the controller runs a query on the database producing a ResultSet ( lets call it rs )

All this is working fine. What i need to do now is access the data stored in the ResultSet called rs via the use of a bean and writing it out in the jsp page.

I suppose what i need to know is:

1. Within the bean, how do i access the ResultSet.
2. How do i access certain columns withing the ResultSet (ie firstName )
3. how do i loop through the ResultSet to display/write all rows returned?

I hope o have made this clear enough.
Thanking you for your help rashidkamranbs.
0
 

Author Comment

by:dgeorgio
ID: 6911791
Yes, thankyou that all makes sense but I am unsure how i access the information stored in the ResultSet with the use of the bean and the jsp.

This is currently what i have.

I have a servlet that when invoked by the controller runs a query on the database producing a ResultSet ( lets call it rs )

All this is working fine. What i need to do now is access the data stored in the ResultSet called rs via the use of a bean and writing it out in the jsp page.

I suppose what i need to know is:

1. Within the bean, how do i access the ResultSet.
2. How do i access certain columns withing the ResultSet (ie firstName )
3. how do i loop through the ResultSet to display/write all rows returned?

I hope o have made this clear enough.
Thanking you for your help rashidkamranbs.
0
 

Author Comment

by:dgeorgio
ID: 6911908
Yes, thankyou that all makes sense but I am unsure how i access the information stored in the ResultSet with the use of the bean and the jsp.

This is currently what i have.

I have a servlet that when invoked by the controller runs a query on the database producing a ResultSet ( lets call it rs )

All this is working fine. What i need to do now is access the data stored in the ResultSet called rs via the use of a bean and writing it out in the jsp page.

I suppose what i need to know is:

1. Within the bean, how do i access the ResultSet.
2. How do i access certain columns withing the ResultSet (ie firstName )
3. how do i loop through the ResultSet to display/write all rows returned?

I hope o have made this clear enough.
Thanking you for your help rashidkamranbs.
0
 

Author Comment

by:dgeorgio
ID: 6912140
Yes, thankyou that all makes sense but I am unsure how i access the information stored in the ResultSet with the use of the bean and the jsp.

This is currently what i have.

I have a servlet that when invoked by the controller runs a query on the database producing a ResultSet ( lets call it rs )

All this is working fine. What i need to do now is access the data stored in the ResultSet called rs via the use of a bean and writing it out in the jsp page.

I suppose what i need to know is:

1. Within the bean, how do i access the ResultSet.
2. How do i access certain columns withing the ResultSet (ie firstName )
3. how do i loop through the ResultSet to display/write all rows returned?

I hope o have made this clear enough.
Thanking you for your help rashidkamranbs.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question