code: public static Connection makeCollector (final Connection conn, final List<Statement> stmts)
      {
          return (Connection)Proxy.newProxyInstance(
              Connection.class.getClassLoader(), PROXY_IFACES, new InvocationHandler() {
              public Object invoke (Object proxy, Method method, Object[] args) throws Throwable {
                  Object result = method.invoke(conn, args);
                  if (result instanceof Statement) {
                      stmts.add((Statement)result);
                  }
                  return result;
              }
          });
      }
docs: Wraps the given connection in a proxied instance that will add all statements returned by
  methods called on the proxy (such as {@link Connection#createStatement}) to the supplied
  list. Thus you can create the proxy, pass the proxy to code that creates and uses statements
  and then close any statements created by the code that operated on that Connection before
  returning it to a pool, for example.