异常日志:
!Nutz SQL Error: 'SELECT avg(tem) as tem FROM base_station_actual_data b WHERE b.tem!=999999 AND b.date_time >= '2018-02-09' AND b.date_time < '2018-02-10' AND substring(b.date_time, 12, 2) IN ('07', '09', '10') AND b.station_id_c='C1523''
PreparedStatement:
'SELECT avg(tem) as tem FROM base_station_actual_data b WHERE b.tem!=999999 AND b.date_time >= ? AND b.date_time < ? AND substring(b.date_time, 12, 2) IN ('07', '09', '10') AND b.station_id_c=?'
CaseMessage=Before start of result set
代码:
//根据传入日期获取农作物过去十天平均温度
public double getTemAvgPast10Days(String past10date,String date,String stationCode){
String sqlStr="SELECT "+
"avg(tem) as tem "+
"FROM "+
"base_station_actual_data b "+
"WHERE "+
"b.tem!=999999 "+
"AND b.date_time >= @past10date "+
"AND b.date_time < @date "+
"AND substring(b.date_time, 12, 2) IN ('07', '09', '10') "+
"AND b.station_id_c=@stationCode ";
//测试
past10date="2018-02-09";
date="2018-02-10";
Sql sql = Sqls.queryRecord(sqlStr);
sql.params().set("past10date", past10date);
sql.params().set("date", date);
sql.params().set("stationCode", "C1523");
sql.setCallback(new SqlCallback() {
public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
double result=0.0;
String resultStr=rs.getString("tem");
result=Double.parseDouble(resultStr);
return result;
}
});
nutDao.execute(sql);
return sql.getDouble();
}