Solved

MVC - Looping through a ResultSet

Posted on 2002-03-29
7
705 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 52
Eclipse with gitlab 1 40
eclipse apache tomcat admin console 52 96
eclipse console opening separately 2 17
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 …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

776 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