Spring's Stored Procedure - results coming back from procedure always empty

后端 未结 2 1573
遥遥无期
遥遥无期 2020-12-14 11:14

I am using Spring\'s JdbcTemplate and StoredProcedure classes. I am having trouble getting the stored procedure class to work for me.

I have a stored procedure on a

相关标签:
2条回答
  • 2020-12-14 11:16

    The problem is simple if you don't pass a RowMapper while declaring the outparam which is a CURSOR. Spring is going to return {} I.e empty cursor.

     declareParameter(new SqlOutParameter("output", OracleTypes.CURSOR)); - returns empty {}
     declareParameter(new SqlOutParameter("output", OracleTypes.CURSOR, new ApplicationMapper()); - returns result
    

    Where ApplicationMapper is my custom mapper which implements RowMapper.

    0 讨论(0)
  • 2020-12-14 11:40

    The problem here is that Oracle's way of doing stored procedures is not JDBC compliant. Oracle's SPs return resultset data via OUT parameters or return values that are cursors, and they have to be handled specially. This means you cannot use any of Spring's JDBC stuff that assumes compliance with JDBC, you have to do it yourself.

    In practice, this means you have to use JdbcTemplate and CallableStatementCallback, which means a lot more manual JDBC coding than you'd ideally like, but I've yet to find a way to avoid this.

    On a slight aside, I rather suspect that the JDBC spec was written to conform closely to the Sybase (and, by association, SQL Server) way of doing things, because the way stored procedures are handled in JDBC is a remarkably good fit for those systems (and a poor fit for Oracle's).

    0 讨论(0)
提交回复
热议问题