You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by bu...@apache.org on 2004/03/04 16:01:02 UTC
DO NOT REPLY [Bug 27438] New: -
JDBCAppender doesn't release connection in case of failure
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