public void query(String sql,StatementVisitor statement,ResultSetVisitor resultsetVisitor) throws SQLException {
  Connection connection=null;
  PreparedStatement stmt=null;
  ResultSet resultSet=null;
  try {
    connection=source.getConnection();
    stmt=connection.prepareStatement(sql);
    if (statement != null) {
      statement.visit(stmt);
    }
    resultSet=stmt.executeQuery();
    while (resultSet.next()) {
      if (!resultsetVisitor.visit(resultSet)) {
        return;
      }
    }
    resultSet.close();
  }
  finally {
    SQLUtil.closeQuietly(resultSet);
    SQLUtil.closeQuietly(stmt);
    SQLUtil.closeQuietly(connection);
  }
}

public void query ( String sql , StatementVisitor statement , ResultSetVisitor resultsetVisitor ) throws SQLException { Connection connection = null ; PreparedStatement stmt = null ; ResultSet resultSet = null ; try { connection = source . getConnection ( ) ; stmt = connection . prepareStatement ( sql ) ; if ( statement != null ) { statement . visit ( stmt ) ; } resultSet = stmt . executeQuery ( ) ; while ( resultSet . next ( ) ) { if ( ! resultsetVisitor . visit ( resultSet ) ) { return ; } } resultSet . close ( ) ; } finally { SQLUtil . closeQuietly ( resultSet ) ; SQLUtil . closeQuietly ( stmt ) ; SQLUtil . closeQuietly ( connection ) ; } }
perform sql query and let visitor handle results . if the sql string contains ? placeholders , use the statementvisitor to update the preparedstatement with actual values .
