Example usage for org.springframework.jdbc.core JdbcOperations query

List of usage examples for org.springframework.jdbc.core JdbcOperations query

Introduction

In this page you can find the example usage for org.springframework.jdbc.core JdbcOperations query.

Prototype

<T> List<T> query(String sql, RowMapper<T> rowMapper, @Nullable Object... args) throws DataAccessException;

Source Link

Document

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

Usage

From source file:org.danann.cernunnos.sql.QueryTask.java

public void perform(TaskRequest req, TaskResponse res) {
    final DataSource dataSource = DataSourceRetrievalUtil.getDataSource(dataSourcePhrase, connectionPhrase, req,
            res);//from  w ww  . j  ava 2 s . c o m

    final SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
    final JdbcOperations jdbcOperations = jdbcTemplate.getJdbcOperations();

    //Setup the parameter setter and row callback handler for this task and the request/response
    final PreparedStatementSetter preparedStatementSetter = new PhraseParameterPreparedStatementSetter(
            this.parameters, req, res);
    final ResponseMappingRowCallbackHandler rowCallbackHandler = new ResponseMappingRowCallbackHandler(this,
            req, res);

    //Get the SQL and run the query
    final String finalSql = (String) sql.evaluate(req, res);
    jdbcOperations.query(finalSql, preparedStatementSetter, rowCallbackHandler);

    if (rowCallbackHandler.getRowCount() == 0) {
        this.performSubtasks(req, res, this.emptyResult);
    }
}