Menu

Problem in batch execution

RohitVohra
2004-12-06
2013-04-11
  • RohitVohra

    RohitVohra - 2004-12-06

    Hi,

    I'm currently using IBatis version 2.0.3. I'm not able to work upon with Batch. I'm doing the following :

    sqlMap.startBatch();
    sqlMap.insert(....);
    sqlMap.update(....);
    int rows = sqlMap.executeBatch();
    System.out.println("Number of rows affected = "+rows);

    And it is always showing 0.

    I debugged and found that when executeBatch is being executed, following code snippet  :

    public int executeBatch(SessionScope session)
    throws SQLException {
    int rows = 0;
    Batch batch = (Batch) session.getBatch();
    if (batch != null) {
    try {
    rows = batch.executeBatch();
    } finally {
    batch.cleanupBatch();
    }
    }
    return rows;
    }

    it gets batch = null, and is not able to process the batch.

    I'm using build 333 for IBatis.

    Please let me know how to get the number of rows updated through a batch.  I'm not able to get the exact picture as to why this is happening. Please help. It's critical for my project.

    Thanks in advance.
    Rohit

     
    • Clinton Begin

      Clinton Begin - 2004-12-06

      > I'm currently using IBatis version 2.0.3. I'm not able to work upon with Batch. I'm
      > doing the following :
      > sqlMap.startBatch();

      Are you starting a the transaction too?  So...

      startTransaction()
      startBatch()
      insert...
      update...
      executeBatch()
      commitTransaction()
      endTransaction

      PS:  I answered this on the incubator list for you.  Did you have trouble receiving it?

      Clinton

       
    • RohitVohra

      RohitVohra - 2004-12-07

      Hi Clinton..

                  I'm not having access to mailing list / incubator. It's banned bcz of our company internet policy.

        Anyhow, I had started the transaction also for batch processing, still it returns no. of rows updated = 0. When I looked into the code, I found that when the preparedStatement.executeBatch() is being called in the private Batch class contained in SqlExecuter, and in executeBatch method of this private class, following line :

      int[] rowCounts = ps.executeBatch();

          All the int array elements contain -2, which means Success but No. of rows updated unknown. It's not returning the number of rows updated.

           I looked for it on internet, and found the following something similar :

      http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=3&t=004071

      Am not able to make how to get the number of rows updated.

      Thanks,
      Rohit

       

Log in to post a comment.