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)
上一篇 2022年7月26日 下午10:16
下一篇 2022年7月26日 下午10:16


相关推荐

  • ClassCastException。

    ClassCastException。这个错误也很常见,通常在程序中出现强制类型转换时出现这个错误,如下面这段代码所示:publicstaticMapm=newHashMap(){ { put("a","2"); } }; publicstaticvoidmain(String[]args){ IntegerisInt=(Integer)m.get("a"…

    2025年10月11日
    2
  • FusionChartsFree及其教程「建议收藏」

    FusionChartsFree及其教程「建议收藏」今天在群里有人发了这个东西,主是FLASH图表控件,看到标题说是支持多种语言的,就下下来试了下,呵呵。。发现还真的很有用。。。先记下来。。以后可用于自己做的项目中。。同时也上网找到一本《FusionChartsFree中文开发指南.pdf》,同时也上传上来吧。。。…

    2022年7月13日
    18
  • UML类图—01

    UML类图—01

    2021年7月12日
    83
  • Mysql 多表联合查询效率分析及优化

    Mysql 多表联合查询效率分析及优化1.多表连接类型1.笛卡尔积(交叉连接)在MySQL中可以为CROSSJOIN或者省略CROSS即JOIN,或者使用’,’如:SELECT*FROMtable1CROSSJOINtable2SELECT*FROMtable1JOINtable2SELECT*FROMtable1,table2由于其返回的结果为被连接的两…

    2022年4月28日
    36
  • shmget物理内存_共享内存的常用函数详解shmget shmat

    shmget物理内存_共享内存的常用函数详解shmget shmat共享内存区域是被多个进程共享的一部分物理内存 如果多个进程都把该内存区域映射到自己的虚拟地址空间 则这些进程就都可以直接访问该共享内存区域 从而可以通过该区域进行通信 共享内存是进程间共享数据的一种最快的方法 一个进程向共享内存区域写入了数据 共享这个内存区域的所有进程就可以立刻看到其中的内容 这块共享虚拟内存的页面 出现在每一个共享该页面的进程的页表中 但是它不需要在所有进程的虚拟内存中都有相同

    2025年9月23日
    3
  • 春运里的“车轮战”:每天60多道工序保养轮对

    春运里的“车轮战”:每天60多道工序保养轮对

    2021年6月29日
    113

发表回复

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

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