spring-framework / org.springframework.jdbc.core.namedparam / NamedParameterJdbcOperations / queryForObject

queryForObject

@Nullable abstract fun <T : Any> queryForObject(sql: String, paramSource: SqlParameterSource, rowMapper: RowMapper<T>): T

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping a single result row to a Java object via a RowMapper.

Parameters

sql - SQL query to execute

paramSource - container of arguments to bind to the query

rowMapper - object that will map one object per row

Exceptions

org.springframework.dao.IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row

org.springframework.dao.DataAccessException - if the query fails

Return
the single mapped object (may be null if the given RowMapper returned null)

@Nullable abstract fun <T : Any> queryForObject(sql: String, paramMap: MutableMap<String, *>, rowMapper: RowMapper<T>): T

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping a single result row to a Java object via a RowMapper.

Parameters

sql - SQL query to execute

paramMap - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)

rowMapper - object that will map one object per row

Exceptions

org.springframework.dao.IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row

org.springframework.dao.DataAccessException - if the query fails

Return
the single mapped object (may be null if the given RowMapper returned null)

@Nullable abstract fun <T : Any> queryForObject(sql: String, paramSource: SqlParameterSource, requiredType: Class<T>): T

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object.

The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.

Parameters

sql - SQL query to execute

paramSource - container of arguments to bind to the query

requiredType - the type that the result object is expected to match

Exceptions

org.springframework.dao.IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row

org.springframework.dao.DataAccessException - if the query fails

Return
the result object of the required type, or null in case of SQL NULL

See Also
org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class)

@Nullable abstract fun <T : Any> queryForObject(sql: String, paramMap: MutableMap<String, *>, requiredType: Class<T>): T

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object.

The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.

Parameters

sql - SQL query to execute

paramMap - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)

requiredType - the type that the result object is expected to match

Exceptions

org.springframework.dao.IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row

org.springframework.dao.DataAccessException - if the query fails

Return
the result object of the required type, or null in case of SQL NULL

See Also
org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class)