• 2 replies
  • Latest Post - ‏2012-02-13T07:22:15Z by Rajesh V
4447 Posts

Pinned topic PreparedStatement and executeBatch()

‏2002-01-08T20:24:22Z |

I am trying to insert records into the database using the addBatch() and
executeBatch() methods. I am using PreparedStatement. And I am trying to insert
52 records at a time.
I have the records in an array, and I am looping through the array, setting the
parameters for the prepared statement and doing addBatch(). And finally when I
come out of the loop I call preparedStatement.executeBatch().
int[] updateCounts = ps.executeBatch();
Here it is throwing out the ArrayIndexOutOfBoundsException. Anybody has any
idea why this is happening? This works fine with the Statement object, but it
is with the PreparedStatement that I am having this problem. I am using JDK
1.3. My database is DB2 UDB 7.1 and my driver is IBM DB2 ODBC Driver.

thanks in advance,
Updated on 2012-02-13T07:22:15Z at 2012-02-13T07:22:15Z by Rajesh V
  • SystemAdmin
    4447 Posts

    RE: PreparedStatement and executeBatch()

    sjsjdk sjdfskdj
    Updated on 2002-06-18T20:07:15Z at 2002-06-18T20:07:15Z by SystemAdmin
  • Rajesh V
    Rajesh V
    1 Post

    Re: PreparedStatement and executeBatch()


    I'm also facing the simillar problem:

    For Example : I have 2 rows to be inserted into DB2. if I insert the 2 rows one by one my code is inserting the data properly.

    Where as if I use PreparedStatement.addBatch() and call preparedStatement.executeBatch(), the code is failing .

    Here is my code:
    PreparedStatement pstmt = con.prepareStatement("SQL Query Here");
    pstmt.setString(1, "adfdfd");
    pstmt.setString(2, "dfghdfg");
    pstmt.setString(3, "rtyrhj");

    pstmt.setString(1, "Rajesh");
    pstmt.setString(2, "V");
    pstmt.setString(3, "678");
    int[] a = pstmt.execuetBatch();

    The error message i am getting is : Non-atomic batch failure. The batch was submitted, but at least one exception occurred on an individual member of the batch. Use getNextException() to retrieve the exceptions for specific batched elements.

    Error Code : -301
    Message : Error for batch element #0: DB2 SQL error: SQLCODE: -301, SQLSTATE: 42895, SQLERRMC: 4

    I'm using DB2 on windows:

    JDBC Driver Details:
    MajorVersion : 9
    ProductVersion : DSN09015
    DriverMajorVersion : 2
    MinorVersion : 3
    DriverName : IBM DB2 JDBC Universal Driver Architecture
    Any Help is really appreciated.

    Thanks in Advance!