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


相关推荐

  • 在pycharm中如何使用anaconda环境进行编辑_pycharm中导入pygame

    在pycharm中如何使用anaconda环境进行编辑_pycharm中导入pygame目录一.简单使用二:如何打包工程中的使用到的其他文件(如,excel,cfg等)三.通过pyinstaller打包后的resources,如何找到呢一.简单使用1.在虚拟环境中,添加pyinstallerlib2.将pyinstallertool加入到pycharm的externtool中-D,–onedirCreateaone-fold…

    2022年8月27日
    6
  • C++\QT常见面试题[通俗易懂]

    C++\QT常见面试题[通俗易懂]1.C与C++的区别2.深拷贝和浅拷贝的区别3.指针和引用的区别4.什么是面向对象,面向对象的三大特征是什么?5.static关键字的用法6.const关键字的用法7.什么是函数重载8.创建的对象有几种方式,有什么区别9.什么是构造函数10.什么是this指针11.抽象类是什么12.什么是封装、继承、多态13.私有继承,保护继承和公有继承的区别14.友元函数15.new和delete16.C++STL容器有哪些17.什么是面向对象编程的开放封闭原则?18.内联函数与宏的区

    2022年6月25日
    93
  • 常用webservice方法_太极拳初学入门的基本要领

    常用webservice方法_太极拳初学入门的基本要领1.什么是webservice先来考虑一个问题,如果我们要在自己的程序里面展示天气预报,那怎么弄?正确的做法是我们发送一个请求到一个系统,他会给我们返回来天气情况。这个就是一个webservice。天气预报系统就相当于webservice的服务端,我们的系统就相当于客户端。2.如何调用别人发布的webservice

    2022年9月21日
    3
  • Python中常用的第三方库_vscode如何使用第三方库

    Python中常用的第三方库_vscode如何使用第三方库第10章Python第三方库使用1.Python第三方库的获取和安装1.1pip工具安装1.2自定义安装1.3文件安装1.4pip工具使用2.pyinstaller库概述3.pyinstaller库与程序打包4.jieba库概述5.jieba库与中文分词6.wordcloud库概述7.wordcloud库与可视化词云1.Python第三方库的获取和安装Python第三方库依照安装方式灵活性和难易程度有3个方法,这3个方法是:pip工具安装、

    2022年10月14日
    3
  • 关于oracle的备份 导入[通俗易懂]

    关于oracle的备份 导入

    2022年1月19日
    56
  • PCI PCI-X PCI-E区别「建议收藏」

    PCI PCI-X PCI-E区别「建议收藏」PCIPCI-XPCI-E区别

    2022年5月30日
    40

发表回复

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

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