tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ALEXANDROS KOTSIRAS" <ALEXANDRO...@prodigy.net>
Subject Re: Help me !
Date Wed, 12 Jul 2000 04:02:51 GMT
Yes you can reuse the same connnection in different methods whtithin the
same dbBean or JSP (you should not have Connections inside JSP though) . You
can then loop through multiple ResultSets (and this should probably be in
your JSP file)  by using the same connection. In the end of you JSP close
(or free to your Pool) Connection-PreparedStatemets-Resultsets.
You can even reuse the same PreparedStatemt with multiple ResultSets, I
always do  preparedStatement.clearParameters() before i reuse it but it
might not be necessary
But in this case you won't be able to loop through your first Resultset if
you reused the same PreapredStatement to create a second ResultSet. This is
usefull if your first Query returns only 1 row so that you can retrieve the
values before reusing the PreparedStament , or if your first SqL is
Insert/Update/Delete and does not produce a ResultSet at all.





----- Original Message -----
From: Darren Lee Deliang <just_darren@hotmail.com>
To: <tomcat-user@jakarta.apache.org>
Sent: Wednesday, July 12, 2000 7:17 AM
Subject: RE: Help me !


>
> I did declare the con as :
>
> private Connection con = null;
>
> but it posed no problems in my other jsp pages..
>
> Another qn, is it possible to establish only one Connection object to my
db
> (con) and use it for different methods in my class? for example method A
> wants to access and read some data from Table A in my db while method B
will
> access and WRITE to Table B in my db. Can I use the same con or do I need
to
> declare several?
>
> Darren
>
> >From: Bob Byron <bbyron@MailAndNews.com>
> >Reply-To: tomcat-user@jakarta.apache.org
> >To: "Darren Lee Deliang" <just_darren@hotmail.com>,    tomcat-user
> ><tomcat-user@jakarta.apache.org>
> >Subject: RE: Help me !
> >Date: Tue, 11 Jul 2000 12:03:28 -0400
> >
> >I would suspect your variable "con" is null.  If you want a quick check,
I
> >would insert System.out.println("Connection=" + con); before line 253.
> >
> >If it displays "Connection=null", you will want to reexamine the
> >initialization of con.
> >
> >------------------------------------------------------------
> >Bob Byron
> >RAD Systems, Inc.
> >(972)516-4256
> >
>
> ________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
>


Mime
View raw message