Search code examples
sqldb2websphere

DB2 - ERRORCODE=-4229, SQLSTATE=null


I'm using a batch class in EJB to INSERT more than 100 rows in the same commit using the command line executeBatch in the DB2.

When I execute the command shows this error: ERRORCODE=-4229, SQLSTATE=null.

The ID sequence is IDENTITY clause on the CREATE TABLE.

Table:

   CREATE TABLE table (col1 INT,
                       col2 DOUBLE,
                       col3 INT NOT NULL GENERATED ALWAYS AS IDENTITY)

Does anyone have any idea?

ERROR:

Caused by: nested exception is: com.ibm.db2.jcc.am.BatchUpdateException: [jcc][t4][102][10040][4.24.97] Batch failure. The batch was submitted, but at least one exception occurred in an individual batch member.
Use getNextException() to retrieve exceptions for specific batch elements. ERRORCODE=-4229, SQLSTATE=null

Solution

  • It's not an answer, but a suggestion to handle Db2 exceptions to have an ability to deal with such errors.
    If you are unable to rewrite your error handling, the only thing you can to is to enable JDBC trace on the client or/and set the Db2 dbm cfg DIAGLEVEL parameter to 4.

    PreparedStatement pst = null;
    try 
    {
        pst = ...;
        ...
        int [] updateCounts = pst.executeBatch();
        System.out.println("Batch results:");
        for (int i = 0; i < updateCounts.length; i++) 
          System.out.println("  Statement " + i + ":" + updateCounts[i]);
    } catch (SQLException ex) 
    {
        while (ex != null) 
        {
          if (ex instanceof com.ibm.db2.jcc.DB2Diagnosable) 
          {
            com.ibm.db2.jcc.DB2Diagnosable db2ex = com.ibm.db2.jcc.DB2Diagnosable) ex;
            com.ibm.db2.jcc.DB2Sqlca sqlca = db2ex.getSqlca();
            if (sqlca != null) 
            {
              System.out.println("SQLCODE: " + sqlca.getSqlCode());
              System.out.println("MESSAGE: " + sqlca.getMessage());
            } 
            else 
            {
              System.out.println("Error code: " + ex.getErrorCode());
              System.out.println("Error msg : " + ex.getMessage());
            }
          } 
          else 
          {
            System.out.println("Error code (no db2): " + ex.getErrorCode());
            System.out.println("Error msg  (no db2): " + ex.getMessage());
          }
          if (ex instanceof BatchUpdateException) 
          {
            System.out.println("Contents of BatchUpdateException:");
            System.out.println(" Update counts: ");
            System.out.println(" Statement.SUCCESS_NO_INFO: " + Statement.SUCCESS_NO_INFO);
            System.out.println(" Statement.EXECUTE_FAILED : " + Statement.EXECUTE_FAILED); 
          
            BatchUpdateException buex = (BatchUpdateException) ex;
            int [] updateCounts = buex.getUpdateCounts(); 
            for (int i = 0; i < updateCounts.length; i++) 
              System.out.println("  Statement " + i + ":" + updateCounts[i]);
          }
          ex = ex.getNextException();
        }
    }
    ...