Accessing stored procedure's multiple result sets in Apache Camel

I am building a proof of concept for using Apache Camel. I am trying to build a route that will call the stored procedure on a Sybase DB using JDBC component and then process its multiple results sets.

So far, I have the following configuration using Spring:

<camelContext id="context">
    <route>
        <from uri="direct:start"/>
        <bean ref="sqlStatementCreator"/>
        <to uri="jdbc:dataSource?resetAutoCommit=false"/>
        <bean ref="sqlResultsProcessor"/>
    </route>
</camelContext>

The sqlStatementCreator is a simple class with only one method that returns String containing the sql statement to execute stored procedure:

{call sp_name ('some arg')}

The stored procedure returns 2 (or more) result sets with the data that I need.

The question is how to access those results sets in the sqlResultsProcessor?

The documentation for JDBC components states that "the result is returned in the OUT body as an ArrayList>". That works perfectly if stored procedure returns only one result set. However, in case of multiple result sets when I check the Exchange's body in the sqlResultsProcessor I have null.

  • Maybe the Camel cannot return multiple results sets in the OUT body with JDBC component?
  • Maybe it is better to write a custom bean to access the DB that will process results and put them into the OUT body?
  • Or maybe I am completely missing something?
  • Apache Camel version is 2.9.2.

    I had to add the resetAutoCommit=false option to the jdbc component, because otherwise the exception was thrown by Sybase:

    com.sybase.jdbc3.jdbc.SybSQLException: Stored procedure 'sp_name' may be run only in unchained transaction mode.
    

    And I cannot change the stored procedure. It is the way it is.


    As I have found out myself, Apache Camel (v.2.9.0) currently does not support processing of multiple results sets with JDBCProducer . As you can see in the source code of JDBCProducer in the processingSql* methods:

    if (stmt.execute(sql)) {
        rs = stmt.getResultSet();
        setResultSet(exchange, rs);
    }
    

    After executing SQL statement producer gets first ResultSet and sets it to Exchange.

    Therefore, if you need to process multiple ResultSets it is better to write your own bean that will execute SQL and process its results.

    链接地址: http://www.djcxy.com/p/74414.html

    上一篇: 将结果集从SQL数组转换为字符串数组

    下一篇: 在Apache Camel中访问存储过程的多个结果集