Class ResultIterator<T>

  extended by javatools.datatypes.PeekIterator<T>
      extended by javatools.database.ResultIterator<T>
All Implemented Interfaces:, java.lang.Iterable<T>, java.util.Iterator<T>

public class ResultIterator<T>
extends PeekIterator<T>

This class is part of the Java Tools (see It is licensed under the Creative Commons Attribution License (see by the YAGO-NAGA team (see This class wraps a ResultSet into an Iterator over a given Class. It requires a method that can wrap a row of a ResultSet into an object of the given class.

  // We need this class to define how to construct an Employer from a table row
  public static class EmployerWrapper implements ResultWrapper<Employer> {

     // Wraps the current row in a ResultSet into an Employer
     public Employer wrap(ResultSet r) {  
       return(new Employer(r.getString(1),r.getDouble(2)); 


  Database d=new OracleDatabase("scott","tiger");
  for(Employer e : d.query("SELECT * FROM employers WHERE salary>1000",
                           new EmployerConstructor())) {

Nested Class Summary
static interface ResultIterator.ResultWrapper<T>
          Wraps the current row in a ResultSet into a T
Nested classes/interfaces inherited from class javatools.datatypes.PeekIterator
PeekIterator.ElementaryPeekIterator<T>, PeekIterator.SimplePeekIterator<T>
Field Summary
static ResultIterator.ResultWrapper<java.lang.Boolean> BooleanWrapper
          ResultWrapper for a single Boolean column
static ResultIterator.ResultWrapper<java.lang.Double[]> DoublesWrapper
          ResultWrapper for several Doubles.
static ResultIterator.ResultWrapper<java.lang.Double> DoubleWrapper
          ResultWrapper for a single Double column.
static ResultIterator.ResultWrapper<java.lang.Integer[]> IntegersWrapper
          ResultWrapper for several Integers.
static ResultIterator.ResultWrapper<java.lang.Integer> IntegerWrapper
          ResultWrapper for a single Integer column
static ResultIterator.ResultWrapper<java.lang.Long> LongWrapper
          ResultWrapper for a single Long column.
static ResultIterator.ResultWrapper<java.lang.String[]> StringsWrapper
          ResultWrapper for String columns
static ResultIterator.ResultWrapper<java.lang.String> StringWrapper
          ResultWrapper for a single String column
Fields inherited from class javatools.datatypes.PeekIterator
closed, initialized, next
Constructor Summary
ResultIterator(java.sql.ResultSet s, ResultIterator.ResultWrapper<T> cons)
          Creates a ResultIterator for a ResultSet
Method Summary
 void close()
          Closes the resultset and the underlying statement
 void finalize()
          Closes the resultset
 T internalNext()
          Returns the next or NULL if no next element is available
Methods inherited from class javatools.datatypes.PeekIterator
asList, asList, asSet, asSet, asSet, emptyIterator, hasNext, iterator, list, list, main, next, nextOrNull, numElements, numElements, peek, remove, toString, toString, toString
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

Field Detail


public static final ResultIterator.ResultWrapper<java.lang.Boolean> BooleanWrapper
ResultWrapper for a single Boolean column


public static final ResultIterator.ResultWrapper<java.lang.String> StringWrapper
ResultWrapper for a single String column


public static final ResultIterator.ResultWrapper<java.lang.String[]> StringsWrapper
ResultWrapper for String columns


public static final ResultIterator.ResultWrapper<java.lang.Long> LongWrapper
ResultWrapper for a single Long column. Returns NULL for NULL


public static final ResultIterator.ResultWrapper<java.lang.Double> DoubleWrapper
ResultWrapper for a single Double column. Returns NULL for NULL


public static final ResultIterator.ResultWrapper<java.lang.Double[]> DoublesWrapper
ResultWrapper for several Doubles. Returns NULL for NULL


public static final ResultIterator.ResultWrapper<java.lang.Integer> IntegerWrapper
ResultWrapper for a single Integer column


public static final ResultIterator.ResultWrapper<java.lang.Integer[]> IntegersWrapper
ResultWrapper for several Integers. Returns NULL for NULL

Constructor Detail


public ResultIterator(java.sql.ResultSet s,
                      ResultIterator.ResultWrapper<T> cons)
Creates a ResultIterator for a ResultSet

Method Detail


public T internalNext()
               throws java.lang.Exception
Description copied from class: PeekIterator
Returns the next or NULL if no next element is available



public void close()
Closes the resultset and the underlying statement

Specified by:
close in interface
close in class PeekIterator<T>


public void finalize()
Closes the resultset

finalize in class java.lang.Object