SERVLET.RRWD
Release JDBC resources when done
Description
This rule flags JDBC resources that are not released when they are finished.
Failing to close and release JDBC connections can cause other users to experience long waits for connections. Although a JDBC connection that is left unclosed will be reaped and returned by WebSphere Application Server after a timeout period, others may have to wait for this to occur.
Close JDBC statements when you are through with them. JDBC ResultSets can be explicitly closed as well. If not explicitly closed, ResultsSets are released when their associated statements are closed.
Example
package SERVLET;
import java.sql.*;
public class RRWD {
void test0 () {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection ("some url");
stmt = conn.createStatement();
rs = stmt.executeQuery ("some query");
} catch (Exception e) {}
finally {
try {
// should have rs.close () and stmt.close ()
} catch (Exception e) {}
}
}
}
Repair
Ensure that your code is structured to close and release JDBC resources in all cases, even in exception and error conditions.
Reference
IBM WebSphere Application Server Standard and Advanced Editions, Harvey W. Gunther.
http://www-4.ibm.com/software/webservers/appserv/ws_bestpractices.pdf
|