Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query for Double with Spring JDBC template query

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

like image 996
s5804 Avatar asked Jun 15 '10 09:06

s5804


2 Answers

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);
}
like image 57
Edward Dale Avatar answered Sep 22 '22 11:09

Edward Dale


public double getAverageScore() {
    return jdbctemplate.queryForObject("select avg(score) from test", Double.class);
}
like image 24
Chris J Avatar answered Sep 21 '22 11:09

Chris J