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

哈哈 阅读:777 2021-03-31 21:35:49 评论:0

数据库获取统计参数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;

声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号