org.springframework.jdbc.core
Class SingleColumnRowMapper

java.lang.Object
  extended by org.springframework.jdbc.core.SingleColumnRowMapper
All Implemented Interfaces:
RowMapper

public class SingleColumnRowMapper
extends Object
implements RowMapper

RowMapper implementation that converts a single column into a single result value per row. Expects to work on a ResultSet that just contains a single column.

The type of the result value for each row can be specified. The value for the single column will be extracted from the ResultSet and converted into the specified target type.

Since:
1.2
Author:
Juergen Hoeller
See Also:
JdbcTemplate.queryForList(String, Class), JdbcTemplate.queryForObject(String, Class)

Constructor Summary
SingleColumnRowMapper()
          Create a new SingleColumnRowMapper.
SingleColumnRowMapper(Class requiredType)
          Create a new SingleColumnRowMapper.
 
Method Summary
protected  Object getColumnValue(ResultSet rs, int index)
          Retrieve a JDBC object value for the specified column.
 Object mapRow(ResultSet rs, int rowNum)
          Implementations must implement this method to map each row of data in the ResultSet.
 void setRequiredType(Class requiredType)
          Set the type that each result object is expected to match.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingleColumnRowMapper

public SingleColumnRowMapper()
Create a new SingleColumnRowMapper.

See Also:
setRequiredType(java.lang.Class)

SingleColumnRowMapper

public SingleColumnRowMapper(Class requiredType)
Create a new SingleColumnRowMapper.

Parameters:
requiredType - the type that each result object is expected to match
Method Detail

setRequiredType

public void setRequiredType(Class requiredType)
Set the type that each result object is expected to match.

If not specified, the column value will be exposed as returned by the JDBC driver.


mapRow

public Object mapRow(ResultSet rs,
                     int rowNum)
              throws SQLException
Description copied from interface: RowMapper
Implementations must implement this method to map each row of data in the ResultSet. This method should not call next() on the ResultSet, but extract the current values.

Specified by:
mapRow in interface RowMapper
Parameters:
rs - the ResultSet to map
rowNum - The number of the current row
Throws:
SQLException - if a SQLException is encountered getting column values (that is, there's no need to catch SQLException)

getColumnValue

protected Object getColumnValue(ResultSet rs,
                                int index)
                         throws SQLException
Retrieve a JDBC object value for the specified column.

The default implementation uses the getObject method. Additionally, this implementation includes a "hack" to get around Oracle returning a non-standard object for their TIMESTAMP datatype.

Parameters:
rs - is the ResultSet holding the data
index - is the column index
Returns:
the Object returned
Throws:
SQLException
See Also:
JdbcUtils.getResultSetValue(java.sql.ResultSet, int)


Copyright (c) 2002-2005 The Spring Framework Project.