org.apache.commons.dbutils
Class ResultSetIterator

java.lang.Object
  extended by org.apache.commons.dbutils.ResultSetIterator
All Implemented Interfaces:
Iterator<Object[]>

public class ResultSetIterator
extends Object
implements Iterator<Object[]>

Wraps a ResultSet in an Iterator. This is useful when you want to present a non-database application layer with domain neutral data.

This implementation requires the ResultSet.isLast() method to be implemented.


Constructor Summary
ResultSetIterator(ResultSet rs)
          Constructor for ResultSetIterator.
ResultSetIterator(ResultSet rs, RowProcessor convert)
          Constructor for ResultSetIterator.
 
Method Summary
 boolean hasNext()
          Returns true if there are more rows in the ResultSet.
static Iterable<Object[]> iterable(ResultSet rs)
          Generates an Iterable, suitable for use in for-each loops.
 Object[] next()
          Returns the next row as an Object[].
 void remove()
          Deletes the current row from the ResultSet.
protected  void rethrow(SQLException e)
          Rethrow the SQLException as a RuntimeException.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResultSetIterator

public ResultSetIterator(ResultSet rs)
Constructor for ResultSetIterator.

Parameters:
rs - Wrap this ResultSet in an Iterator.

ResultSetIterator

public ResultSetIterator(ResultSet rs,
                         RowProcessor convert)
Constructor for ResultSetIterator.

Parameters:
rs - Wrap this ResultSet in an Iterator.
convert - The processor to use when converting a row into an Object[]. Defaults to a BasicRowProcessor.
Method Detail

hasNext

public boolean hasNext()
Returns true if there are more rows in the ResultSet.

Specified by:
hasNext in interface Iterator<Object[]>
Returns:
boolean true if there are more rows
Throws:
RuntimeException - if an SQLException occurs.

next

public Object[] next()
Returns the next row as an Object[].

Specified by:
next in interface Iterator<Object[]>
Returns:
An Object[] with the same number of elements as columns in the ResultSet.
Throws:
RuntimeException - if an SQLException occurs.
See Also:
Iterator.next()

remove

public void remove()
Deletes the current row from the ResultSet.

Specified by:
remove in interface Iterator<Object[]>
Throws:
RuntimeException - if an SQLException occurs.
See Also:
Iterator.remove()

rethrow

protected void rethrow(SQLException e)
Rethrow the SQLException as a RuntimeException. This implementation creates a new RuntimeException with the SQLException's error message.

Parameters:
e - SQLException to rethrow
Since:
DbUtils 1.1

iterable

public static Iterable<Object[]> iterable(ResultSet rs)
Generates an Iterable, suitable for use in for-each loops.

Parameters:
rs - Wrap this ResultSet in an Iterator.
Returns:
an Iterable, suitable for use in for-each loops.


Copyright © 2002-2011 The Apache Software Foundation. All Rights Reserved.