Search code examples
javastored-proceduresjava-stored-procedures

CallableStatement for DB2 StoredProcedure throws BadSqlGrammarException - Descriptor index not valid (10>9)


Stored Procedure: CALL STORED_PROCEDURE_PROCESS_ONE_TIME(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

Stored Procedure Variables:

d Stored_Procedure_Process_One_Time_...
d                 pi
d xterm                          4  0 const
d xdate                          8  0 const
d xsid                          10    const
d xctrnum                        9  0 const
d xpnum                          3  0 const
d xsnum                         11  0 const
d xaflag                         1    const
d xprecv                         5  0 const
d xpScn                          5  0 const
d xptime                         6  0 const
d xzipcde                       11    const
d xlchname                      10    const
d xlchusr                       10    const

My Java Code for the Callable Statement [There is no output]:

CallableStatement cs = con.prepareCall(theStoredProcedure);
    cs.setInt(1, 11);
    cs.setInt(2,  20230327);
    cs.setString(3, "NN84567");
    cs.setInt(4, 123);
    cs.setInt(5, 15);
    cs.setInt(6, 849223);
    cs.setString(7, Constants.SP_Y_FLAG);
    cs.setInt(8, 23);
    cs.setInt(9, 57);
    cs.setInt(10, 175255);
    cs.setString(11, "90210");
    cs.setString(12, Constants.USER);
    cs.setString(13, "Matt");
    return cs;
}, (CallableStatementCallback) cs -> {
    cs.execute();
    return true;
}), recover -> {
    log.warn("Exception occurred while making procedure call", recover.getLastThrowable());
    throw new CheckedException("Exception occurred while making procedure call", recover.getLastThrowable());
});

Exception: "stack_trace":"<#b6ebaa11> o.s.j.BadSqlGrammarException: CallableStatementCallback; bad SQL grammar []; nested exception is java.sql.SQLException: Descriptor index not valid. (10>9)

It sets the 9th value but when it goes to set the int for the 10th parameter I'm receiving the above SQL Exception.


Solution

  • the stored procedure given to me was the wrong one. I was getting the error because it only had 9 elements instead of 13. Thanks for everyone's help.