If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > PreparedStatement.executeBatch() is failed with Error code: -301

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Feb 2012
Posts: 3
PreparedStatement.executeBatch() is failed with Error code: -301

Hi Friends,

I am new to this Forum, and I amd facing a stange problem while executing batch of SQL staments using PreparedStatement.executeBatch().

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.addBatch();

pstmt.setString(1, "Rajesh");
pstmt.setString(2, "V");
pstmt.setString(3, "678");
pstmt.addBatch();
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!

Rajesh
Reply With Quote
  #2 (permalink)  
Old
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,649
What's your table definition ?

What's your zOS DB2 version ?
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Feb 2012
Posts: 3
Hi,
Thanks for your reply .

Please find the info below:

DatabaseProductName : DB2
DatabaseMajorVersion : 9
DatabaseMinorVersion : 1
DatabaseProductVersion : DSN09015
DriverMajorVersion : 2
DriverMinorVersion : 3
JDBCMajorVersion : 3
JDBCMinorVersion : 0
DriverName : IBM DB2 JDBC Universal Driver Architecture
DriverVersion : 2.3.63

In actual senario , I have a table with 12 columns with one PK column.

10 Varchar columns, 1 Date type and another one is Timestamp which is our PK column.

If I insert data one by one row using preparedStatment.executeUpdate(), its working fine, where as its giving errors for preparedStatement.executeBatch().

Thanks
Rajesh
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 3,230
How did you gave the values of the date column and the timestamp(PK) column in your INSERT statement?

Last edited by tonkuma; 02-13-12 at 09:17. Reason: Add date column.
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
Join Date: Feb 2012
Posts: 3
Hi,

I'm taking the values from Oracle and inserting them in DB2.

If I insert row by row using preparedStatement.executeUpdate(), my code is inserting the records properly. Where as If I use preparedStatement.executeBatch(), my code is failing with the above error code.

Thanks,
Rajesh
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On