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
Lee Fesperman - 27 Apr 2007 19:12 GMT
> ResultSet r = ..."select field1, field2,...money_field,... from tab1
> where...";
[quoted text clipped - 9 lines]
> }
> p.submitBatch();
What is submitBatch()? It's not a standard JDBC method.
--
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
Zachi - 27 Apr 2007 22:48 GMT
> > ResultSet r = ..."select field1, field2,...money_field,... from tab1
> > where...";
[quoted text clipped - 17 lines]
> * The Ultimate DBMS is here!
> * FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
submitBatch(), as well as its brothers addBatch(), executeBatch() and
clearBatch() are part
of the java.sql.Statement , which has been part of the standard since
1.4.2 (if not earlier). This is an interface to allow sending a batch
of commands to be executed, instead of sending them one at a time,
which allows for much higher performance due to eliminating a lot of
roundtrips.
Zachi
david@smooth1.co.uk - 28 Apr 2007 09:12 GMT
> > > ResultSet r = ..."select field1, field2,...money_field,... from tab1
> > > where...";
[quoted text clipped - 29 lines]
>
> - Show quoted text -
Log a bug with IBM.
David Harper - 28 Apr 2007 10:37 GMT
>>> ResultSet r = ..."select field1, field2,...money_field,... from tab1
>>> where...";
[quoted text clipped - 23 lines]
> which allows for much higher performance due to eliminating a lot of
> roundtrips.
submitBatch isn't listed in the API docs for java.sql.Statement in Java
1.4.2 or 1.5.0 or 1.6.0
The only batch methods listed are addBatch, clearBatch and executeBatch.
Perhaps submitBatch is some kind of non-standard extension in the
Informix driver?
David Harper
Cambridge, England
Zachi - 28 Apr 2007 11:52 GMT
> >>> ResultSet r = ..."select field1, field2,...money_field,... from tab1
> >>> where...";
[quoted text clipped - 34 lines]
> David Harper
> Cambridge, England
Sorry, my mistake. submitBatch() was a wrapper for executeBatch() in
my original code.