java.math.BigDecimal cannot be cast to java.lang.Integer(BigDecimal转为Integer类型)
java.math.BigDecimal cannot be cast to java.lang.Integer(BigDecimal转为Integer类型)
·
问题描述:
利用sql语句从数据库里面取出数据后,对取出的数据进行数据转换时,出现了java.math.BigDecimal cannot be cast to java.lang.Integer错误。
原因是BigDecimal不能直接转换为Integer类型。
解决方法:
先将取出的数据转换为BigDecimal类型,再将该类型转换为Integer类型,参考代码如下所示:
BigDecimal bigDecimal= (BigDecimal)objects[0];
Integer id=Integer.parseInt(bigDecimal.toString());
参考:https://blog.csdn.net/y_bccl27/article/details/94178765
更多推荐
所有评论(0)