Possible Bug in Informix JDBC Driver with use of addBatch() with BigDecimal
Posted in 2007
Hello all, I am observing strange behavior in use of batch inserts of BigDecimal (money type in Informix): occasionally, instead of the null value the previous non-null value of the field in the batch will be used. This problem arises whether I set it the field implicitly or explicitly, and does not appear if the insert is executed immediately. The driver is 3.0JC3, and it happens on Sun Java on Windows XP and IBM java bundled with Informix on Linux.Here is a code to describe the problem: ResultSet r = ..."select field1, field2,...money_field,... from tab1 where..."; PreparedStatement p = ..."insert into tab2 (field1, field2,...money_field,...) values (?,?,...?,...)"; //implicit NULL setting - inserts non-null values while (r.hasNext()) { ... p.setBigDecimal(i,r.getBigDecimal(i)); ... p.addBatch(); } p.submitBatch(); //explicit NULL setting - inserts non-null values while (r.hasNext()) { ... BigDecimal b = r.getBigDecimal(i); if (r.wasNull()) { p.setNull(i, java.sql.Types.BigDecimal); } else { p.setBigDecimal(i,b); } ... p.addBatch(); } p.submitBatch(); // non-use of batch - works with implicit and explicit while (r.hasNext()) { ... p.setBigDecimal(i,r.getBigDecimal(i)); ... p.execute(); } Any ideas? Thanks, Zachi