Skip to content

Add JdbcTemplate.queryForObject(String, PreparedStatementSetter, RowMapper ) [SPR-4965] #9640

@spring-projects-issues

Description

@spring-projects-issues

Glenn Gilbert opened SPR-4965 and commented

Currently, the 'queryForObject' series there is not a method that includes a PreparedStatementSetter. There are options such as queryForObject(String,Object[],RowMapper), but it doesn't allow other features of accessing a preparedStatement. (ie ps.setMaxRows(n) etc)

the code would be:

<code>
/**

  • Query given SQL to create a prepared statement from SQL and a
  • PreparedStatementSetter implementation that knows how to bind values to the
  • query, mapping a single result row to a Java object via a RowMapper.
  • @param sql SQL query to execute
  • @param pss object that knows how to set values on the prepared statement.
  If this is null, the SQL will be assumed to contain no bind
  parameters. Even if there are no bind parameters, this object may be
  used to set fetch size and other performance options.
  • @param rowMapper object that will map one object per row
  • @return the single mapped object
  • @throws IncorrectResultSizeDataAccessException if the query does not return
  exactly one row DataAccessException if the query fails

*/
public Object queryForObject(String sql, PreparedStatementSetter pss, RowMapper rowMapper) throws DataAccessException {

List results = getJdbcTemplate().query(sql, pss, rowMapper);
return DataAccessUtils.singleResult(results);

}
</code>


No further details from SPR-4965

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: dataIssues in data modules (jdbc, orm, oxm, tx)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions