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>
ResultSetHandler
implementation that converts one
ResultSet
column into an Object. This class is thread safe.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
The column number to retrieve.private final String
The column name to retrieve. -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates a new instance of ScalarHandler.ScalarHandler
(int columnIndex) Creates a new instance of ScalarHandler.private
ScalarHandler
(int columnIndex, String columnName) Helper constructorScalarHandler
(String columnName) Creates a new instance of ScalarHandler. -
Method Summary
-
Field Details
-
columnIndex
private final int columnIndexThe column number to retrieve. -
columnName
The column name to retrieve. Either columnName or columnIndex will be used but never both.
-
-
Constructor Details
-
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
Creates a new instance of ScalarHandler.- Parameters:
columnName
- The name of the column to retrieve from theResultSet
.
-
ScalarHandler
Helper constructor- Parameters:
columnIndex
- The index of the column to retrieve from theResultSet
.columnName
- The name of the column to retrieve from theResultSet
.
-
-
Method Details
-
handle
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:
SQLException
- if a database access error occursClassCastException
- if the class datatype does not match the column type- See Also:
-