logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 27438] New: - JDBCAppender doesn't release connection in case of failure
Date Thu, 04 Mar 2004 15:01:02 GMT
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: log4j-dev@jakarta.apache.org
        ReportedBy: gtesei@yahoo.com


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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message