Connection        connection = borrowConnection(); PreparedStatement statement  = null; ResultSet         resultSet  = null; List              result     = new ArrayList();  try { statement = connection.prepareStatement(sql);  int paramIdx = 1;  for (Iterator iter = parameters.iterator(); iter.hasNext(); paramIdx++) { statement.setObject(paramIdx, iter.next()); } resultSet = statement.executeQuery();  int rowIdx = 0;  for (Iterator it = createResultSetIterator(model, resultSet, queryHints); ((end < 0) || (rowIdx <= end)) && it.hasNext(); rowIdx++) { if (rowIdx >= start) { result.add(it.next()); } } } catch (SQLException ex) {  closeStatement(statement); returnConnection(connection); throw new DynaSqlException("Error while fetching data from the database", ex); } return result;
return fetch(model, sql, (Table[])null, 0, -1);
    public List fetch(Database model, String sql, Collection parameters, Table[] queryHints, int start, int end) throws DynaSqlException    {        Connection        connection = borrowConnection();        PreparedStatement statement  = null;        ResultSet         resultSet  = null;        List              result     = new ArrayList();        try        {            statement = connection.prepareStatement(sql);            int paramIdx = 1;            for (Iterator iter = parameters.iterator(); iter.hasNext(); paramIdx++)            {                statement.setObject(paramIdx, iter.next());            }            resultSet = statement.executeQuery();            int rowIdx = 0;            for (Iterator it = createResultSetIterator(model, resultSet, queryHints); ((end < 0) || (rowIdx <= end)) && it.hasNext(); rowIdx++)            {                if (rowIdx >= start)                {                    result.add(it.next());                }            }        }        catch (SQLException ex)        {            // any other exception comes from the iterator which closes the resources automatically            closeStatement(statement);            returnConnection(connection);            throw new DynaSqlException("Error while fetching data from the database", ex);        }        return result;    }