A practical suggestion is to add some debugging code to the csv file and create a log and close the result sets. You could later examine this file and see if there is a βclosingβ entry for each βcreationβ.
So, if you have a utility class with static methods that allows you to write lines to a file, you can do this as follows:
ResultSet rs = stmt.executeQuery(query); Util.writeln(rs.hashcode() + ";create"); // add this line whenever a // new ResultSet is created
and
rs.close(); Util.writeln(rs.hashcode() + ";closed"); // add this line whenever a // ResultSet is closed
Open the csv file using Excel or any other program with extended sheets, sort the table and see if the result sets are closed. If so, add additional debugging information to clearly identify open sets.
BTW. Wrapping interfaces (like JAMon) is pretty simple, if you have an eclipse or something else, it is encoded in less than 15 minutes. You will need to wrap Connection, Statement (and PreparedStatement?) And ResultSet, the ResultSet wrapper can be used to track and monitor the creation and closing of result sets:
public MonitoredConnection implements Connection { Connection wrappedConnection = null; public MonitoredConnection(Connection wrappedConnection) { this.wrappedConnection = wrappedConnection; }
The same for MonitoredStatement and MonitoredResultSet (MonitoredStatement will return wrapped ResultSets):
public MonitoredStatement implements Statement { private Statement wrappedStatement = null; @Override public ResultSet executeQuery(String sql) throws SQLException MonitoredResultSet rs = wrappedStatement.executeQuery(sql); ResultSetMonitor.create(rs.getWrappedResultSet());
and
public MonitoredResultSet implements ResultSet { private ResultSet wrappedResultSet; @Override public void close() { wrappedResultSet.close(); ResultSetMonitor.close(wrappedResultSet);
In the end, you will only need to change one line in the code:
Connection con = DriverManager.getConnection(ur);
to
Connection con = new MonitoredConnection(DriverManager.getConnection(ur));