Re: RE: Error in servlet

From: Peter Mount <peter(at)retep(dot)org(dot)uk>
To: Andreas Tille <tillea(at)rki(dot)de>
Cc: chris markiewicz <cmarkiew(at)commnav(dot)com>, "'PostgreSQL General'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: RE: Error in servlet
Date: 2000-09-18 19:48:05
Message-ID: Pine.LNX.4.21.0009182046460.454-100000@maidast.demon.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 15 Sep 2000, Andreas Tille wrote:

> On Thu, 14 Sep 2000, chris markiewicz wrote:
>
> > could this be a servlet/thread issue? i cannot tell from the code snippet,
> Solved. I really stupidly forgot an rs.next() :-(((.
>
> > but remember that variables in a servlet with class scope are essentially
> > static. (i am guessing that query, rs, stmt, etc are all class scope. this
> > is very dangerous, in the programming sense of the word...) i've had
> > similar (but not the same) problems before. as a general rule, i NEVER put
> > a class scope variable in a servlet unless i really mean to.
> Well, that might be true for query and rs and I'll change that, but
> in my opinion
>
> public class ServletSQLClass
> {
> private Connection con;
> private Statement stmt;
>
> ...
> con = DriverManager.getConnection(url,user,passwd);
> stmt = con.createStatement();
> ...
> }
>
> con and stmt have to be class scope to hold the connection to the
> database and don't have to reopen over and over. Or did I understand
> something wrong?

IMHO, only Connection should be of class scope, as you can create as many
Statement/PreparedStatements as you want.

Peter

--
Peter T Mount peter(at)retep(dot)org(dot)uk http://www.retep.org.uk
PostgreSQL JDBC Driver http://www.retep.org.uk/postgres/
Java PDF Generator http://www.retep.org.uk/pdf/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Erich K. Oliphant 2000-09-18 19:53:15 Oracle Conversions Tools
Previous Message The Hermit Hacker 2000-09-18 18:38:37 Re: WTF is going on with PG_VERSION?