May 2015
Intermediate to advanced
234 pages
4h 18m
English
In this recipe, we will add a DAO method to quickly get the number of results for an SQL query without actually loading the rows in the memory.
Use an SQL count(*) function and get the value directly using the queryForObject() method with a second argument specifying Long as the returned type:
public long countMinorUsers() {
String sql = "select count(*) from age < 18";
return jdbcTemplate.queryForObject(sql, Long.class);
}Read now
Unlock full access