How to convert a list object to bigdecimal in prepared statement?
Posted
by
user1103504
on Stack Overflow
See other posts from Stack Overflow
or by user1103504
Published on 2012-11-01T10:58:53Z
Indexed on
2012/11/01
11:00 UTC
Read the original article
Hit count: 207
I am using prepared statement for bulk insertion of records. Iam iterating a list which contains values and their dataTypes differ. One of the data type is BigDecimal and when i try to set calling preparedstatement, it is throwing null pointer exception.
My code
int count = 1;
for (int j = 0; j < list.size(); j++) {
if(list.get(j) instanceof Timestamp) {
ps.setTimestamp(count, (Timestamp) list.get(j));
} else if(list.get(j) instanceof java.lang.Character) {
ps.setString(count, String.valueOf(list.get(j)));
}
else if(list.get(j) instanceof java.math.BigDecimal) {
ps.setBigDecimal(count, (java.math.BigDecimal)list.get(j));
} else {
ps.setObject(count, list.get(j));
}
count++;
}
I tried 2 ways to convert, casting the object and tried to create a new object of type BigDecimal
ps.setBigDecimal(count, new BigDecimal(list.get(j).toString));
both donot solve my problem. It is throwing null pointer exception.
help is appreciated.
Thanks
© Stack Overflow or respective owner