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

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

Introduction

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

Prototype

Map<String, Object> queryForMap(String sql, @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, expecting a result map.

Usage

From source file:net.solarnetwork.node.dao.jdbc.test.DatabaseSetupTest.java

@Test
public void createDatabaseSetup() {
    DatabaseSetup setup = new DatabaseSetup();
    setup.setDataSource(dataSource);/*from   w  w  w.j a  va 2  s  .  co m*/
    setup.setInitSqlResource(new ClassPathResource("derby-init.sql", DatabaseSetup.class));
    setup.init();

    JdbcOperations jdbcOps = new JdbcTemplate(dataSource);
    Map<String, ?> results = jdbcOps.queryForMap("SELECT * FROM solarnode.sn_settings WHERE skey = ?",
            "solarnode.sn_settings.version");
    log.debug("Got sn_settings.version record {}", results);
    assertNotNull(results);
    assertEquals("Should have key, value, type, flags, and modified values", 5, results.size());
    assertEquals("5", results.get("svalue"));
}