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,
This topic has been locked.
2 replies Latest Post - 2012-02-13T07:22:15Z by Rajesh V
Pinned topic PreparedStatement and executeBatch()
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
Updated on 2012-02-13T07:22:15Z at 2012-02-13T07:22:15Z by Rajesh V
Rajesh V 270002RJKF1 PostACCEPTED ANSWER
Re: PreparedStatement and executeBatch()2012-02-13T07:22:15Z in response to SystemAdminHi,
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");
int a = pstmt.execuetBatch();
The error message i am getting is :
com.ibm.db2.jcc.b.vd: 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!