This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi. I am working with DB2 7.2 on NT. I use a preparedStatement to insert a lot of records so I use the addBatch statement. The performance is good when using addBatch but in some rows a column is changed :|, I mean, supouse record 1 as column1_1 column1_2 column1_3 and record 2 as column2_1 column2_2 column2_3 after the inserts using batch I got somting like column1_1 column2_2 column1_3 column2_1 column2_2 column2_3 It happends with some rows only. If I use prepStmt.executeUpdate() instead of prepStmt.addBatch() it works ok, but slower Any Idea ?. Thanks
The column that has the problem is: stmt.setString(4, (String) nombreTrab.trim()); I am sure that it is asigned becouse if I change the stmt.addBatch() to stmt.executeUpdate() it works. A friend told me that he has the same problem with char columns, JDBC type 3 (net) from IBM DB2 7, I am not sure but it seems to be a bug on the driver. He told me that they had to contact IBM support, maybe I'll try this. Thanks
Joined: Jan 07, 2003
I am not sure if I was wrong or IBM driver. I used the batch like this:
so that each 10000 rows process the batch and continue with next rows. I changed it to:
And it works. The JDBC API dose not say that you have to close a PreparedStatement after executing a batch. Maybe is a bug on DB2 JDBC, maybe i did not read all.
Do you have autocommit enabled or disabled? If you have it enabled (the default) I'd try disabling it and adding some explicit commits. If you can, try committing every individual update, and then try committing every 10,000 update. [ March 17, 2004: Message edited by: Loren Rosen ]
Joined: Jan 07, 2003
I am using autocommit off. I do not think that the problem could be with commit becouse if I execute the statement executeBatch() after adding all batch (addBatch) I do not have any problem. But if I use addBatch() (100 times, for example), executeBatch() and, with the same statement (with out closing the statemet) clearBatch(), addBatch() (100 time, for example) and again executeBatch() The problem apears. If I close the statement after each executeBatch() I got no problem, like in the first case, using executeBatch() only at the end.