Look into CachedRowSets of JDBC 2.0 (check java.sun.com). That way you can
close the connection and still be able to use the resultset.
-Tim

-----Original Message-----
From: Ashwin Jacob Mathew [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 21, 2001 3:16 AM
To: [EMAIL PROTECTED]
Subject: Re: Passing a resultset from a servlet to jsp


true, you could do it using the session, but i would not advise that in this
situation. the session is meant for persisting information across user
calls. in this case, it looks like you just need to pass data from servlet
to JSP in the course of a single user call - you should use the
setAttribute() and getAttribute() methods on HttpServletRequest.

also, keep in mind that ResultSets must ALWAYS be closed once you're done
with them. if you don't do this, and you're using connection pooling (who
doesn't?) you're going to be in big trouble - it's equivalent to a memory
leak. in projects i've worked on, we copy the ResultSet out to a temporary
data structure (like an  array, although we typically use more sophisticated
wrappers around that), close the ResultSet immediately, and send the data
structure over to the JSP.

ashwin

-----Original Message-----
From: Peter Huber [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 21, 2001 1:40 PM
To: [EMAIL PROTECTED]
Subject: Re: Passing a resultset from a servlet to jsp


Hi,

I suppose you have a session runing if you`re in your servlet. Simply
append your array to that session (can't remember the method name, but
it's simple to find in javadocs). After forwarding to jsp you have
access to the same session you previously accessed in your servlet. You
can simply get the array (or whatever datastruct) and start your
processing.
Be carefull with directly using the ResultSet object as datatransfer
object. I think a ResultSet is not guranteed to live forever as it
depends on a connection which may be timeouted somewhen.

Peter
----- Original Message -----
From: "Kwan, William" <[EMAIL PROTECTED]>
Date: Tuesday, November 20, 2001 8:52 pm
Subject: Passing a resultset from a servlet to jsp

> Hi,
>
> I tried to put the resultset into an array and send that to the
> jsp page but
> I think I'm doing it wrong. Is there an easier way, like passing the
> resultset over??
>
> here some code:
> does this set the rsArray to have the data from the resultset??
>        request.setAttribute(dbrs.getString(i+1), rsArray);
>
>        RequestDispatcher rd =
> getServletContext().getRequestDispatcher("/test/display.jsp");
>        rd.forward(request, response);
>
> thanks,
> Will
>
>
________________________________________________________________________
___
> To unsubscribe, send email to [EMAIL PROTECTED] and include in
> the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http:
> Resources: http://java.sun.com/products/servlet/external-
> resources.htmlLISTSERV Help:
> http://www.lsoft.com/manuals/user/user.html
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to