Results 1 to 5 of 5
  1. #1
    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

  2. #2
    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.

  3. #3
    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

  4. #4
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,479
    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.

  5. #5
    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

Posting Permissions

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