-----------------------------
Please read the FAQ!
<http://java.apache.org/faq/>
-----------------------------


Hi,

  This is a bit off topic, isn't it ?


On Sat, 18 Sep 1999, mskang wrote:
m| java api says resultset are automatically closed when its statement
m| closed.
m| then, are statement automatically closed when its connection closed ?
m| and, if i call destroy() at end of service(), would opened connection
m| closed automatically ?

I would never rely on this. JDBC drivers tend to be buggy :-)
So enclose _any_ statement in
----
 ResultSet rset = null;
 Statement stmt = null;
 try {
  stmt = get_new_statemet_from_connection;
  rset = stmt.executeQuery("...");
  // do some work
 }
 finally {
   if (rset != null) rset.close()
   if (stmt != null) stmt.close()
 }
----

Unless your servlets are not much frequented, opening a connection at the
beginning of service() and closing it at the end usually become a
performance problem since opening may take several seconds. Instead,
allocate a pool of preopened connections in your init()-method. 
Take one connection from the pool at the beginning of the service() method
and return it at the end. When returning it, you have to make sure, that
the connection is 'in a clean state' since it may be reused over and over 
again, so you should close all your statements (e.g. with the codesnippet
above).

I've written a FIFO-based pool myself to do this but there are several
pool-implementations out there which may help you to use this technique
without much efford.

ciao,
 -hen
---
Henner Zeller                                 [EMAIL PROTECTED]
 PGP pub key [77F75B39]: finger [EMAIL PROTECTED] 
 
  Microsoft is not the answer, it's the question. The answer is 'NO'



--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to