开发者

How to query for Double with Spring JDBC template query

开发者 https://www.devze.com 2023-01-03 17:36 出处:网络
How do one query for a 开发者_StackOverflow社区double with the Spring JDBC temple? For example: public double getAverageScore() {

How do one query for a 开发者_StackOverflow社区double with the Spring JDBC temple?

For example:

public double getAverageScore() {
    return jdbctemplate.queryFor???("select avg(score) from test");
}

There are queryForInt and queryForLong, but no queryForDouble


I haven't tested this, but queryForObject with Double.class as the last parameter might work.

public double getAverageScore() {
    return jdbctemplate.queryForObject("select avg(score) from test", Double.class);
}


public double getAverageScore() {
    return jdbctemplate.queryForObject("select avg(score) from test", Double.class);
}


public Double avgByCampo(Long param) {
   return simpleJdbcTemplate.queryForObject("SELECT avg(t.campo) FROM table t where t.id_campo = ?", Double.class, param);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号