类型转换错误java.math.BigDecimal cannot be cast to java.lang.String

来源:互联网 发布:知乎城市冷漠 编辑:程序博客网 时间:2024/06/08 15:47

数据库获取统计参数sum()统计值,在代码转化为Integer 时,提示转换失败:java.math.BigDecimal cannot be cast to java.lang.String


解决办法:

List set= util.excuteQuery("select COALESCE(sum(1),0) as times from wlsq_data.home_pet_feeder_timing where gateway_id=? and timing_id=? and del_flag=0  ", objs);if(set !=null && set.size() >0){for(Object obj:set){HashMap<String, Object> map =(HashMap<String, Object>)obj;Integer str = Integer.parseInt(map.get("times").toString());if(str == 0){    result = 0;    }else{    result = str;    }}    }
使用coalesce 函数,解决统计数据为空,默认赋值为0;

0 0
原创粉丝点击