我正在尝试根据某些商家返回boolean
。我在这里使用jdbctemplate。
public boolean dealExistsInInterval(String partyId) {
String sql = "<Query>";
boolean result = getJdbcTemplate().queryForObject(sql, new Object[] {partyId},
new RowMapper<boolean>() { --> **Error here**
public boolean mapRow(ResultSet rs, int rowNum) throws SQLException {
Date startDate = rs.getDate("BBORIGINDATE");
logger.info("Start date :"+startDate);
Date todayDate = new Date();
long diff = todayDate.getTime() - startDate.getTime();
Properties properties = BBUtil.getProperties();
int NO_OF_DAYS = 0;
if (properties != null) {
NO_OF_DAYS = Integer.parseInt(properties.getProperty("NO_OF_DAYS"));
}
logger.info("NO_OF_DAYS:"+NO_OF_DAYS);
logger.info("Number of days between today and latest deal :"+TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS));
return TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS) < NO_OF_DAYS ? true : false;
}
});
return result;
}
编译时错误发生在new RowMapper<boolean>()
。
P.S:这不是基于计数的查询。获得结果集后,我必须执行一些业务逻辑。
答案 0 :(得分:2)
您无法定义基本数据类型的通用规范。您必须使用java.lang.Boolean
包装类:
new RowMapper<Boolean>() {
public Boolean mapRow(ResultSet rs, int rowNum) throws SQLException {
// Code goes here...