Top Description Constructors Methods
org.springframework.jdbc.core

public Class ColumnMapRowMapper

extends Object
implements RowMapper<Map<String, Object>>
Class Inheritance
All Implemented Interfaces
org.springframework.jdbc.core.RowMapper
Imports
java.sql.ResultSet, .ResultSetMetaData, .SQLException, java.util.Map, org.springframework.jdbc.support.JdbcUtils, org.springframework.lang.Nullable, org.springframework.util.LinkedCaseInsensitiveMap

RowMapper implementation that creates a java.util.Map for each row, representing all columns as key-value pairs: one entry for each column, with the column name as key.

The Map implementation to use and the key to use for each column in the column Map can be customized by overriding createColumnMap and getColumnKey, respectively.

Note

By default, ColumnMapRowMapper will try to build a linked Map with case-insensitive keys, to preserve column order as well as allow any casing to be used for column names.

Author
Juergen Hoeller
Since
1.2
See Also
JdbcTemplate#queryForList(String), JdbcTemplate#queryForMap(String)

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected Map<String, Object>

Returns:

the new Map instance
createColumnMap
(int
the column count, to be used as initial capacity for the Map
columnCount
)

Create a Map instance to be used as column map.

protected String

Returns:

the column key to use
getColumnKey
(String
the column name as returned by the ResultSet
columnName
)

Determine the key to use for the given column in the column Map.

protected Object

Returns:

the Object returned
getColumnValue
(ResultSet
the ResultSet holding the data
rs
,
int
the column index
index
)

Retrieve a JDBC object value for the specified column.

public Map<String, Object>
mapRow(ResultSet
the ResultSet to map (pre-initialized for the current row)
rs
,
int
the number of the current row
rowNum
)

Implements org.springframework.jdbc.core.RowMapper.mapRow.

Implementations must implement this method to map each row of data in the ResultSet.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ColumnMapRowMapperback to summary
public ColumnMapRowMapper()

Method Detail

createColumnMapback to summary
protected Map<String, Object> createColumnMap(int columnCount)

Create a Map instance to be used as column map.

By default, a linked case-insensitive Map will be created.

Parameters
columnCount:int

the column count, to be used as initial capacity for the Map

Returns:Map<String, Object>

the new Map instance

See Also
org.springframework.util.LinkedCaseInsensitiveMap
getColumnKeyback to summary
protected String getColumnKey(String columnName)

Determine the key to use for the given column in the column Map.

By default, the supplied column name will be returned unmodified.

Parameters
columnName:String

the column name as returned by the ResultSet

Returns:String

the column key to use

See Also
java.sql.ResultSetMetaData#getColumnName
getColumnValueback to summary
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 data type.

Parameters
rs:ResultSet

the ResultSet holding the data

index:int

the column index

Returns:Object

the Object returned

Annotations
@Nullable
See Also
org.springframework.jdbc.support.JdbcUtils#getResultSetValue
mapRowback to summary
public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException

Implements org.springframework.jdbc.core.RowMapper.mapRow.

Doc from org.springframework.jdbc.core.RowMapper.mapRow.

Implementations must implement this method to map each row of data in the ResultSet. This method should not call next() on the ResultSet; it is only supposed to map values of the current row.

Parameters
rs:ResultSet

the ResultSet to map (pre-initialized for the current row)

rowNum:int

the number of the current row

Returns:Map<String, Object>

the result object for the current row (may be null)

Annotations
@Override
Exceptions
SQLException:
if an SQLException is encountered while getting column values (that is, there's no need to catch SQLException)