Anjan wrote:
> 
> Hi Rodney/John,
> 
> >I'm not sure what is being proposed here, so if this is wrong let me
> >know.  But code that is something like the following is not a good idea:
> >
> >Connection con = pool.getConnection();
> >...do something...
> >con.close();
> >...
> >if (!con.isClosed())
> >  con.close();
> 
> As I said earlier, what I'm doing here is something like this
> 
> void func() {
>     Connection conn = null;
>     try {
>         for (i = 0; i < NUM_DATABASES; ++i) {
>             conn = DriverManager.getConnection(driverURL);
>             // do something with connection .......
>             conn.close();
>         }
>     } // end try
>     catch() {
>         //.
>     }
>     finally {
>         // Try to be sure to clean the resources
>         if (!conn.isClosed()) {
>             conn.close();
>         } // end if
>     } // end finally
> } //end func
> 

I would suggest inverting try/catch/finally and for loop so you have

for
  try
     conn = getConnection
  catch
     ...
  finally
     conn.close()
end for

or if you want the exception to abort the for loop

try
   for
      try
         conn = getConnection
      finally
         conn.close()
   end for
catch

These variation will guarantee that close be called once and only once.

john mcnally

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to