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


相关推荐

  • idea方法注解快捷键_idea生成方法的快捷键

    idea方法注解快捷键_idea生成方法的快捷键人工智能,零基础入门!http://www.captainbed.net/inner对于实体Bean类,比较多繁杂的重复代码内容,比如说get/set方法和toString方法,对于这些idea都是有快捷键的,介绍一下toString方法的自动生成:【1】把光标移到最下面:【2】按键盘alt+insert键,找到toString选项:【3】然后就自动生成了:…

    2025年6月3日
    4
  • Python爬虫超详细讲解(零基础入门,老年人都看的懂)

    Python爬虫超详细讲解(零基础入门,老年人都看的懂)关于Python爬虫的超详细讲解,用例子来给大家一步步分析爬虫的代码原理,由浅入深,老年人来了,我也给你整明白。

    2022年6月14日
    36
  • Cookies的实际存储位置

    Cookies的实际存储位置

    2021年10月12日
    47
  • win10JDK环境变量的配置

    win10JDK环境变量的配置在win10系统下进行jdk环境变量与win7的一些区别,作者踩过一些坑,最后通过网上查找资料才将问题解决,但是网上的资料比较零碎,作者整理一下亲自操作过程并且将步骤详细的写了下来,希望能够帮助需要的人。一、下载安装完成jdk之后,桌面右键此电脑选择属性,进入以下界面,然后选择高级系统设置,进入系统配置二、进入系统配置之后点击环境变量,进入环境变量配置窗口三、此时我们可以看到有用户变量…

    2022年7月21日
    9
  • 记一次kubernetes Evicted的处理[通俗易懂]

    记一次kubernetes Evicted的处理[通俗易懂]背景:事情这样的:kubernetes1.21.3集群。容器运行时containerd。除了K8s-node-06节点。保留这个docker节点有很多原因。比如当时没有想好用什么打包镜像。默认让jenkins打包镜像。还有就是我的gitlab10.8.7版本contarinerd运行时下无法启动。就保留了这个节点运行gitlabpod。当然了也把这个节点设置为了不可调度。不相其他应用调度到这个节点上来!最近一段时间gitlab应用频繁出现Evicted的问题:这样就陷入了一个死循环:我的k8s-

    2022年5月17日
    49
  • freemarker把从后台传来的uct时间格式化展现到前台

    freemarker把从后台传来的uct时间格式化展现到前台freemarker把从后台传来的uct时间格式化展现到前台

    2022年4月23日
    49

发表回复

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

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