views:

61

answers:

2

How do one query for a 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

+4  A: 

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);
}
scompt.com
+4  A: 
public double getAverageScore() {
    return jdbctemplate.queryForObject("select avg(score) from test", Double.class);
}
Chris J
Out of topic, just interesting why Spring have no convenience method for Double and Long, when there is one for Int and Long
s5804