Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2002
    Posts
    4

    Unanswered: db2 batch execution

    I'm trying to do something similar to an upsert on a db2(version 7.2.4) table on a mainframe using batch execution and JDBC. It appears the integer array returned from the executeBatch method is valid only if the first operation(insert or update) is successful; otherwise it is filled with -3's. Is there a fix for this?

  2. #2
    Join Date
    Dec 2002
    Posts
    10
    Can you please post the code?

  3. #3
    Join Date
    Dec 2002
    Posts
    4
    Originally posted by Swaminaathan
    Can you please post the code?
    Code is pretty simply. Here's a snippet:
    while (recordIterator.hasNext()) {
    i++;
    stmt.addBatch(insString);
    int [] updateCounts;
    if (recordIterator.hasNext() == false ||(i % batchSize)==0) {
    updateCounts = stmt.executeBatch();
    db.commit();
    stmt.clearBatch();
    }
    }

    insString is the insert/update string and batchSize is the max number of sql strings batched. Stepping through with a debugger and examining the updateCounts array after the executeBatch() call shows that if the 1st statement fails (i.e. the row already exists on insert or the row doesn't exist on an update) the entire array is set to -3. However if the 1st statement succeeds (i.e the row doesn't exist on an insert or does exist on an update) the rest of the array is properly filled (failed statements show as 0 successful rows show as 1). Hope that explains the situation better.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •