Announcement Announcement Module
No announcement yet.
StoredProcedureItemReader : How to retrieve OUT parameter value ? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • StoredProcedureItemReader : How to retrieve OUT parameter value ?


    We're calling a stored procedure with StoredProcedureItemReader (Spring Batch 2.1.0.RELEASE).

    When the stored procedure fails it returns the error message as an OUT parameter (and not as a SQL Error Code).

    The stored procedure resides on mainframe system and already exists (so we cannot ask for a modification).

    How can we get an OUT value outside of the refCursor ?

    For the moment, we have modified StoredProcedureItemReader.openCursor method in order to retrieve the callableStatement just after the callableStatement.execute().
    We added our method afterCallableStatementExecution.

    So we have :
    public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> 
    	protected void openCursor(Connection con) {
    			boolean results = callableStatement.execute();
    			if (results) {
    	protected void afterCallableStatementExecution(CallableStatement aCallableStatement) throws SQLException {
    And if we want to handle OUT values, we just need to inherit from our StoredProcedureItemReader and override afterCallableStatementExecution method.

    Is there a better method ?

    If no, could you integrate this feature into Spring Batch (should I open a JIRA issue) ?

    Thanks very much

  • #2
    Were you able to figure out a better approach?
    I have the same situation, where the stored procedure returns a REFCursor. And not sure how do I get the resultset out of the cursor in the StoredProcedureItemReader