Search code examples
javaspringspring-dataspring-jdbc

Spring jdbcTemplate retrieve numeric values from query


I have this query for my jdbcTemplate and I wanna get just the long value from the database, what should be fixed here?

String query = "SELECT size from users where name = ? AND type = ?";
long size = jdbcTemplate.query(query, new Object[]{id, type}, (rs, rowNum) -> 
rs.getLong("size"));

Solution

  • long size = jdbcTemplate.queryForObject(query, Long.class);