Solved

MVC - Looping through a ResultSet

Posted on 2002-03-29
7
704 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now