Solved

MVC - Looping through a ResultSet

Posted on 2002-03-29
7
708 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

730 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