DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=27438>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=27438

JDBCAppender doesn't release connection in case of failure

           Summary: JDBCAppender doesn't release connection in case of
                    failure
           Product: Log4j
           Version: 1.2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Appender
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


Hi there, 

I think that in JDBCAppender the method execute could work unsafely 

protected void execute(String sql) throws SQLException {

    Connection con = null;
    Statement stmt = null;

    try {
        con = getConnection();

        stmt = con.createStatement();
        stmt.executeUpdate(sql);
    } catch (SQLException e) {
       if (stmt != null)
             stmt.close();
       throw e;
    }
    stmt.close();
    closeConnection(con);

    //System.out.println("Execute: " + sql);
  }

because if there is an exception,  closeConnection(con) is never called. This
migth be very dangerous in case the sql statement return back exceptions from db
. In this case log4j could make busy a lot of db connections, that never will be
released. I think this implementation could work better. 

protected void execute(String sql) throws SQLException {

                Connection con = null;
                Statement stmt = null;

                try {
                        con = getConnection();

                        stmt = con.createStatement();
                        stmt.executeUpdate(sql);
                } finally {
                        if (stmt != null) {
                                try {
                                        stmt.close();
                                } catch (SQLException e) {  }
                        }
                        closeConnection(con);
                }
        }



Regards, 
           
            Gino Tesei

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

Reply via email to