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

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • ubuntu20.04安装vscode_vs安装路径

    ubuntu20.04安装vscode_vs安装路径Ubuntu安装VScode

    2022年9月17日
    0
  • 加密Excel解密

    加密Excel解密excel文件进行加密,能够保护excel文件的内容,但是有时候我们自己设置的密码,时间久了可能会忘记,或者在网上下载的excel文件或者同事之间转发的excel文件也有加密,这对于我们来说都不是很方便了。想要解密excel文件的加密,需要用到奥凯丰EXCEL解密大师excel加密有两种,它们的解密方法也是不一样的。激活成功教程打开密码,激活成功教程它的方法目前只有通过软件找到正确密码才能进行解密,所以点击进入【找回密码】,选择一种找回方法进行激活成功教程(如果对自己设置的密码还有一些印象,可以使用组合破击..

    2022年6月28日
    38
  • java vimrc_vimrc: 终极 vim 配置, 克隆自: https://github.com/amix/vimrc

    java vimrc_vimrc: 终极 vim 配置, 克隆自: https://github.com/amix/vimrc这个仓库克自https://github.com/amix/vimrc放在oschina上来加速部署,也方便再添加些功能.如何使用:gitclonehttps://git.oschina.net/shrekuu/vimrc.git~/.vim_runtimesh~/.vim_runtime/install_awesome_vimrc.sh更多:这个版本直接加入了~/.vim_ru…

    2022年4月30日
    46
  • 2015-11-01 HTML, CSS, JavaScript, DOM

    2015-11-01 HTML, CSS, JavaScript, DOM

    2021年9月10日
    47
  • 如何偷窥到socket对应的内核缓冲区中有什么数据? 有多少数据?—利用recv的MSG_PEEK和ioctlsocket的FIONREAD

    如何偷窥到socket对应的内核缓冲区中有什么数据? 有多少数据?—利用recv的MSG_PEEK和ioctlsocket的FIONREAD很多时候,应用程序仅仅想知道内核缓冲区中有什么数据,或者想知道有多少数据可读,也就是说,应用程序仅仅想偷窥一下里面的数据,并不是想偷取,那怎么办呢?事实上,我们之前已经大致说过,现在,我们继续来复习一下recv的MSG_PEEK:服务端程序为:#include#include//winsock接口#pragmacomm

    2022年7月23日
    7
  • 虚拟机安装完linux后怎么使用linux_虚拟机ubuntu安装教程

    虚拟机安装完linux后怎么使用linux_虚拟机ubuntu安装教程本篇文章为本人从零开始学习linux的学习心得,其中包含了部署虚拟环境安装linux系统。其中若有错误之处,请读者积极指出,让本人与读者共同进步。第一章部署虚拟环境安装linux系统及配置网路一、linux简介首先在学习linux系统之前,我觉得应该先了解一下linux的来历和发展历程,会让我们对linux充满好奇心,对后续的学习会有帮助。(搬砖):早在20世纪70年代,…

    2022年10月8日
    0

发表回复

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

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