Class ScalarHandler<T>
- java.lang.Object
-
- org.apache.commons.dbutils.handlers.ScalarHandler<T>
-
- Type Parameters:
T
- The type of the scalar
- All Implemented Interfaces:
ResultSetHandler<T>
public class ScalarHandler<T> extends java.lang.Object implements ResultSetHandler<T>
ResultSetHandler
implementation that converts oneResultSet
column into an Object. This class is thread safe.- See Also:
ResultSetHandler
-
-
Field Summary
Fields Modifier and Type Field Description private int
columnIndex
The column number to retrieve.private java.lang.String
columnName
The column name to retrieve.
-
Constructor Summary
Constructors Modifier Constructor Description ScalarHandler()
Creates a new instance of ScalarHandler.ScalarHandler(int columnIndex)
Creates a new instance of ScalarHandler.private
ScalarHandler(int columnIndex, java.lang.String columnName)
Helper constructorScalarHandler(java.lang.String columnName)
Creates a new instance of ScalarHandler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
handle(java.sql.ResultSet rs)
Returns oneResultSet
column as an object via theResultSet.getObject()
method that performs type conversions.
-
-
-
Constructor Detail
-
ScalarHandler
public ScalarHandler()
Creates a new instance of ScalarHandler. The first column will be returned fromhandle()
.
-
ScalarHandler
public ScalarHandler(int columnIndex)
Creates a new instance of ScalarHandler.- Parameters:
columnIndex
- The index of the column to retrieve from theResultSet
.
-
ScalarHandler
public ScalarHandler(java.lang.String columnName)
Creates a new instance of ScalarHandler.- Parameters:
columnName
- The name of the column to retrieve from theResultSet
.
-
ScalarHandler
private ScalarHandler(int columnIndex, java.lang.String columnName)
Helper constructor- Parameters:
columnIndex
- The index of the column to retrieve from theResultSet
.columnName
- The name of the column to retrieve from theResultSet
.
-
-
Method Detail
-
handle
public T handle(java.sql.ResultSet rs) throws java.sql.SQLException
Returns oneResultSet
column as an object via theResultSet.getObject()
method that performs type conversions.- Specified by:
handle
in interfaceResultSetHandler<T>
- Parameters:
rs
-ResultSet
to process.- Returns:
- The column or
null
if there are no rows in theResultSet
. - Throws:
java.sql.SQLException
- if a database access error occursjava.lang.ClassCastException
- if the class datatype does not match the column type- See Also:
ResultSetHandler.handle(java.sql.ResultSet)
-
-