且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spring的存储过程 - 从过程返回的结果始终为空

更新时间:2023-02-05 23:33:17

这里的问题是Oracle执行存储过程的方式不符合JDBC。 Oracle的SP通过OUT参数或返回值作为游标返回结果集数据,并且必须专门处理它们。这意味着你不能使用任何假定符合JDBC的Spring的JDBC东西,你必须自己动手。

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.

实际上,这意味着你必须使用 JdbcTemplate CallableStatementCallback ,这意味着比理想情况下更多的手动JDBC编码,但我还没有找到避免这种情况的方法。

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.

稍微偏离一点,我宁愿怀疑编写的JDBC规范是否与Sybase(以及通过关联,SQL Server)方式紧密相符做事,因为在JDBC中处理存储过程的方式非常适合这些系统(并且不适合Oracle)。

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).