简体   繁体   English

java.sql.ResultSet getBigDecimal为空时

[英]java.sql.ResultSet getBigDecimal when it's null

I'm trying to read from a resultSet a BigDecimal which is null 我正在尝试从resultSet中读取一个为null的BigDecimal

bean.setAuthorizedAmount(res.getBigDecimal(columnIndex++));

and it's giving the following exception 它给出了以下异常

java.sql.SQLException: Fail to convert to internal representation

Can you suggest the simplest code that could simply map on BigDecimal, whether the column is null or not, for instance as you can do for String? 您能否建议最简单的代码,该代码可以简单地映射到BigDecimal上,例如该列是否为null,例如您可以对String进行的操作?

Hope I was clear enough, thanks in advance. 希望我足够清楚,在此先感谢。

This is happen when your column data can not be converted to the BigDecimal or any type you are looking for. 当您的列数据无法转换为BigDecimal或您要查找的任何类型时,就会发生这种情况。 I think you have started columnIndex from 0 in that case you won't be able to get the exact column you want. 我认为您已经从0开始了columnIndex ,那样您将无法获得所需的确切列。 It says java is unable to convert data to BigDecimal from the column value. 它说Java无法将数据从列值转换为BigDecimal

EDIT : 编辑:

As stated by Luiggi Mendoza in comment, it would be much better to use column name instead of column index to avoid such problems and yes it increases the readability as well. 正如Luiggi Mendoza在评论中所述,最好使用列名而不是列索引来避免此类问题,是的,它还可以提高可读性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM