java.math.BigDecimal cannot be cast to java.lang.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/java/article/details/94178765

原文地址:https://www.cnblogs.com/yinyl/p/13226105.html