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


相关推荐

  • UART接口简介_uart接口速度

    UART接口简介_uart接口速度UART即通用异步收发传输器(UniversalAsynchronousReceiver/Transmitter),它是一种串行通信的物理接口形式。它将要传输的资料在串行通信与并行通信之间加以转换。作为把并行输入信号转成串行输出信号的芯片,UART通常被集成于其他通讯接口的连结上。一、UART硬件连接UART有4个pin(VCC,GND,RX,TX),用的TTL电平,低电平为0(0V),高电平为1(3.3V或以上)。如下图:引脚介绍:…

    2022年9月14日
  • eclipse Maven配置[通俗易懂]

    eclipse Maven配置[通俗易懂]简述:现需要在Eclipse中配置Maven插件,同时安装maven应用,配置Maven环境变量,建立Maven管理的工程,并用Maven导入Gson包,编写简易Json输出程序步骤:1.首先到EclipseMarketplace中下载MavenIntegrationforEclipseWTP,如下,之后查看是否成功下载,Win

    2022年5月17日
  • plot绘图颜色_matlab画图plot详细

    plot绘图颜色_matlab画图plot详细所有颜色的名字及值:’aliceblue’:’#F0F8FF’,’antiquewhite’:’#FAEBD7′,’aqua’:’#00FFFF’,’aquamarine’:’#7FFFD4′,’azure’:’#F0FFFF’,’beige’:’#F5F5DC’,’bisque’:’#FFE4C4′,

    2022年10月15日
  • stream.groupingBy多层分组_微信分组名称

    stream.groupingBy多层分组_微信分组名称Stream之Collectors.groupingBy(分组)的使用参考自:https://blog.csdn.net/u014231523/article/details/102535902Collectors.groupingBy配合Stream流使用,可以对集合中一个或多个属性进行分组,分组后还可以做聚合运算。首先把数据放入集合: Productprod1=newProduct(1L,1,newBigDecimal(“15.5″),”面包”,”零食”);Produ

    2022年8月20日
  • Docker安装Nexus3私服以及使用

    Docker安装Nexus3私服以及使用一、Nexus简介二、安装步骤(使用docker)1、搜索Nexus3镜像dockersearchnexus​2、拉取Nexus3镜像dockerpullsonatype/nexus3​3、创建Nexus3容器dockerrun-itd-p8081:8081–privileged=true–namenexus3\-v/data/nexus-data:/var/nexus-data–restar…

    2022年7月13日
  • 软件测试:测试用例

    一、通用测试用例八要素  1、用例编号;  2、测试项目;  3、测试标题;  4、重要级别;  5、预置条件;  6、测试输入;  7、操作步骤;  8、预期输出。二、具体分析通用测试用例八要素  1、用例编号  一般是数字和字符组合成的字符串,可以包括(下划线、单词缩写、数字等等),但是需要注意的是,尽量不要写汉语拼音,因为拼音的意义可能有好几种,有可能会导致乱码;  用例编号具有唯一性和易识…

    2022年4月4日

发表回复

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

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