The following code snippit has always worked well even under heavy load
testing and we are using Oracle 8i.
The Oracle driver is notorious for not implicitly closing connections under Type 2.
Don't know about Type 4 but I wouldn't trust it to close any resource that I have
opened...
HTH,
Greg.
try {
// do something, create connection, statements, result set, etc...
} catch (SQLException e) {
System.err.println("SQLException caught: " + e.getMessage());
} catch (Exception e) {
System.err.println("Exception: " + e.getMessage());
} finally {
try {
if (rs != null) rs.close();
} catch (Exception e) {
System.err.println("Exception caught while closing ResultSet: " +
e.getMessage());
}
try {
if (prepStmt != null) prepStmt.close();
} catch (Exception e) {
System.err.println("Exception caught while closing PreparedStatement:
" + e.getMessage());
}
try {
if (con != null) con.close();
} catch (Exception e) {
System.err.println("Exception caught while closing Connection: " +
e.getMessage());
}
}
>
>
> -----Original Message-----
> From: Abhilash Nair [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, June 06, 2002 10:51 AM
> To: JDJList
> Subject: [jdjlist] Closing Connections!!??
>
>
> 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
>
To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm