ResultSet processing/closure in JSP

S

Simon

Hi,

I am trying to understand the implications of processing a ResultSet
in a JSP given that the ResultSet is created in a servlet, and then
placed in the request to provide access to the JSP.

My confusion is how the closure of the ResultSet is managed. I am
aware that the standard procedure would be to open a connection,
execute a statement, and then process the results, before closing the
connection, statement, and result set in the servlet code. As the
ResultSet object is required by the JSP where should I handle closing
it? It seems very messy to create the ResultSet in the servlet, and
then close it in the JSP.

Any thoughts/suggestions are much appreciated.

Thanks,
Simon
 
H

Heiner Kücker

Simon wrote
Hi,

I am trying to understand the implications of processing a ResultSet
in a JSP given that the ResultSet is created in a servlet, and then
placed in the request to provide access to the JSP.

My confusion is how the closure of the ResultSet is managed. I am
aware that the standard procedure would be to open a connection,
execute a statement, and then process the results, before closing the
connection, statement, and result set in the servlet code. As the
ResultSet object is required by the JSP where should I handle closing
it? It seems very messy to create the ResultSet in the servlet, and
then close it in the JSP.

Any thoughts/suggestions are much appreciated.

Copy the values from the ResultSet in ArrayList of ValueObjects
(no get set methods, public members) or an another collection
structure and give this the jsp.

The processing of the entire ResultSet must to be effected
entirirly in one method in a try catch block with closing
the ResultSet, Statement and Connection in the finally
blocks.

See an example on http://www.netspade.com/articles/java/jdbc.xml

Good luck
--
Heiner Kuecker
Internet: http://www.heinerkuecker.de http://www.heiner-kuecker.de
JSP WorkFlow PageFlow Page Flow FlowControl Navigation: http://www.control-and-command.de
Java Expression Formula Parser: http://www.heinerkuecker.de/Expression.html
CnC Template Technology http://www.heinerkuecker.de/Expression.html#templ
 
W

Wendy S

Simon said:
I am trying to understand the implications of processing a ResultSet
in a JSP given that the ResultSet is created in a servlet, and then
placed in the request to provide access to the JSP.

Jakarta's DBUtils might be useful:
http://jakarta.apache.org/commons/dbutils/examples.html

Otherwise, in the Servlet, go through the results and put them somewhere
else-- a List of JavaBeans with their properties populated, a 2-dimensional
array of Strings, whatever makes sense for the data you're getting back.
 
J

John C. Bollinger

Simon said:
Hi,

I am trying to understand the implications of processing a ResultSet
in a JSP given that the ResultSet is created in a servlet, and then
placed in the request to provide access to the JSP.

My confusion is how the closure of the ResultSet is managed. I am
aware that the standard procedure would be to open a connection,
execute a statement, and then process the results, before closing the
connection, statement, and result set in the servlet code. As the
ResultSet object is required by the JSP where should I handle closing
it? It seems very messy to create the ResultSet in the servlet, and
then close it in the JSP.

Any thoughts/suggestions are much appreciated.

You should be able to safely close the ResultSet in the servlet, after
the RequestDispatcher.forward() (or .include()) invocation returns.
This depends on the RequestDispatcher implementation not performing the
forward / include in a new thread, which you can check in your target
environment by obtaining a stack dump inside the JSP. Do note that
after a .forward(), the servlet must not modify the response object, and
probably shouldn't even attempt to read it.

With that being said, if you are passing a ResultSet to your JSP through
the request, then the JSP code is probably performing more processing
than best practices recommend. Better would be to either process the
ResultSet in the servlet and just pass the values (only) to the JSP, or
to do all the work in custom tags.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top