We usually enclose each attempt to close an object with a try/catch:

try{
    //create connection,etc.
}catch(SQLException sqlExc){
    //handle error
}finally{
try {
    try {
        if(rs != null){
            rs.close();
        } 
     } catch (Exception e){
        log("unable to close resultset");
    }
    try {
        if(prepStmt != null){
            prepStmt.close();
        }
    } catch (Exception e){
        log("unable to close statement");
    }
    try {
        if(con != null){
            con.close();
        }
    } catch (Exception e){
        log("unable to close connection");
    }
} catch(SQLException e) {;}
}


> -----Original Message-----
> From: Mark E. Zawadzki [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, June 06, 2002 11:06 AM
> To: JDJList
> Subject: [jdjlist] Re: Closing Connections!!??
> 
> 
> Are you sure that a SQLException is not being thrown, in some 
> cases, w/in the
> finally ? I see you do an empty catch. 
> --- Abhilash Nair <[EMAIL PROTECTED]> wrote:
> > Hi All:
> > 
> > We are using Oracle Thin Type 4 Driver with Weblogic
> > App Server version 5.1 for our JDBC Connections and
> > use Prepared Statements. We also have specified the
> > maximum connections to be 100 in the weblogic
> > properties and in our DAO's we close the
> > PreparedStatement, ResultSet and Connection in the
> > finally block. But there are STILL instances where the
> > connections are not being closed even when the
> > following code is executed:
> > 
> > try{
> >   //create connection,etc.
> > }catch(SQLException sqlExc){
> >   //handle error
> > }finally{
> >   try {
> >      if(rs != null){
> >        rs.close();
> >      }
> >      if(prepStmt != null){
> >        prepStmt.close();
> >      }
> >      if(con != null){
> >        con.close();
> >      }
> >   } catch(SQLException e) {;}
> > }
> > 
> > Problem faced: Exceeding the maximum number of
> > connections due to inactive open connections. Has
> > anyone faced this problem? 
> > 
> > I thought that the finally block is executed no matter
> > what and is the best place to close connections to
> > ensure a proper clean - up! Can anyone please suggest
> > what am I doing wrong here?
> > 
> > Thanks in advance.
> > Abhi
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Yahoo! - Official partner of 2002 FIFA World Cup
> > http://fifaworldcup.yahoo.com
> > 
> > To change your membership options, refer to:
> > http://www.sys-con.com/java/list.cfm
> 
> 
> =====
> Mark Zawadzki Performance Engineer/DBA/Programmer 
> extraordinaire'[EMAIL PROTECTED]  
> [EMAIL PROTECTED]"Programming today is a race between 
> software engineers striving to build bigger and better 
> idiot-proof programs, and the universe trying to build bigger 
> and better idiots. So far, the universe is winningRobert 
> Cringle (columnist, author, host of "Triumph of the Nerds")
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup
> http://fifaworldcup.yahoo.com
> 
> To change your membership options, refer to:
> http://www.sys-con.com/java/list.cfm
> 

To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

Reply via email to