Spring StoredProcedure for Oracle cursor

Spring StoredProcedure for Oracle cursorhttp://forum.springsource.org/archive/index.php/t-24915.htmlPDAViewFullVersion:SqlReturnResultSetvs.SqlOutParameter  lvmMay12th,2006,12:33PMIspentsometimeyest


Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

http://forum.springsource.org/archive/index.php/t-24915.html

PDA

View Full Version : SqlReturnResultSet vs. SqlOutParameter


 

 

lvm
May 12th, 2006, 12:33 PM

I spent some time yesterday trying to call an Oracle stored procedure(function) using the org.springframework.jdbc.object.StoredProcedure class and thought I share what I found.

I got some code from a co-worker that was doing the same thing, but connecting to MS SQLServer. I didn’t have his stored proc to look at for clues.

He was using SqlReturnResultSet:

declareParameter(new SqlReturnResultSet(“rs” new MessageResultExtractor(msgList)));

My Oracle stored proc accepts no inputs and returns a cursor. When I tried to use the code above I kept getting an error like “invalid number or type of arguments”. I looked at the API for SqlReturnResultSet, which states that it is: “Subclass of SqlOutParameter”. But looking at the inheritance stack it shows that it does not! So I figured I needed to declare an SqlOutParameter, which conveniently accepts a ResultSetExtractor. So I used:

declareParameter(new SqlOutParameter(“rs”, OracleTypes.CURSOR, new MessageResultExtractor(msgList))); and it worked!

Note that I had to use the OracleTypes.CURSOR, which I wasn’t sure would work.

I don’t know if there are ways of getting a resultset from an oracle stored procedure other than a cursor, or maybe there’s a way to use SqlReturnResultSet with a cursor, but the SqlOutParameter worked for me.


 

trisberg
May 15th, 2006, 10:50 AM

What you are doing is the best solution. The way Oracle works is different from SQL Server since a stored procedure has to return the cursor/resultset as an explicitly declared ref-cursor out parameter. There is no such restriction in SQL Server so the way we retreive the resultset using standard JDBC API calls is very different for Oracle as compared to SQL Server.

 ==========

注意:

在申明参数时应该按照sp的参数顺序,否则会报错:

PLS-00306: wrong number or types of arguments in call to  

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/164516.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • nginx实现tomcat动静分离详解

    nginx实现tomcat动静分离详解1.为什么要实现动静分离1)nginx的处理静态资源能力超强主要是nginx处理静态页面的效率远高于tomcat的处理能力,如果tomcat的请求量为1000次,则nginx的请求量为6000次,tomcat每秒的吞吐量为0.6M,nginx的每秒吞吐量为3.6M,可以说,nginx处理静态资源的能力是tomcat处理能力的6倍,优势可见一斑。2)动态资源和静态资源分开,使服务器结构更

    2022年6月4日
  • KNN 回归算法_DTW算法

    KNN 回归算法_DTW算法KNN算法也能够用于回归预测。KNN算法用于分类的方法如下:首先,对于一个新来的预测实例,我们在训练集上寻找它的最相近的K个近邻;然后,采用投票法将它分到这K个邻居中的最多的那个类。但是,怎么将KNN算法用于回归呢?其实大致的步骤是一样的,也是对新来的预测实例寻找K近邻,然后对这K个样本的目标值取均值即可作为新样本的预测值。…

    2022年8月21日
  • 游戏开发经验谈(一):游戏架构里隐藏的五个坑及其应对方案

    游戏开发经验谈(一):游戏架构里隐藏的五个坑及其应对方案

    2021年6月10日
  • postMessage详解

    postMessage详解目录一、概述二、详解一、概述作用该方法是HTML5引入的API,可以通过异步方式实现跨源通信,多用于窗口间数据通信。它提供了一种受控机制来规避不同源脚本无法通信的限制,只要正确使用,这种方法很安全。什么是跨源同源即指相同的协议、域名或IP、端口号。浏览器具有同源限制,同源脚本可以相互通信,一般非同源(跨源)的脚本文件禁止相互通信。二、详解语法示例-发送程序&…

    2022年7月15日
  • NSUserDefaults数据保存报错:Attempt to set a non property list object

    NSUserDefaults数据保存报错:Attempt to set a non property list object

    2022年3月12日
  • pycharm2021激活码哔哩哔哩【在线注册码/序列号/破解码】

    pycharm2021激活码哔哩哔哩【在线注册码/序列号/破解码】,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月20日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号