且构网

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

Spring 的存储过程 - 从过程返回的结果总是空的

更新时间:2023-02-05 23:42:25

这里的问题是 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.

在实践中,这意味着您必须使用 JdbcTemplateCallableStatementCallback,这意味着手动 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).