jsp调用存储过程的问题!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

vcdll 2003-05-21 10:26:45
ccreate or replace package jutiPackage is
type test is ref cursor;
function get(sqlstr in varchar2) return test;
end jutiPackage;
/

create or replace package body jutiPackage is
function get(sqlstr in varchar2)
return test
is
mttest test;
str varchar2(80);
begin

if sqlstr = 'y' then ///////////////
open mttest for select * from test8;

else
open mttest for sqlstr;

end if;
return mttest;
end get;
end jutiPackage;
/

我在sqlplus里面的测试语句
declare
out_rs jutiPackage.test;

one test8.test1%type;
two test8.test2%type;
begin
out_rs := jutiPackage.get('y');

fetch out_rs into one ,two;
dbms_output.put_line(one);
dbms_output.put_line(two);
end;
/

测试语句输入后只会显示 :过程创建完毕
怎样才能在sqlpuls里面把结果显示出来

于是我又在JSP里面测试它:
String str = "{? = call jutiPackage.get(?)}";

callable = conn.prepareCall(str);

callable.registerOutParameter(1 , OracleTypes.CURSOR);

callable.setString(2 , "y"); //////////////

callable.execute();

rs = (ResultSet)callable.getObject(1);

while ( rs.next())

out.println(rs.getInt(1));

语句 rs = (ResultSet)callable.getObject(1);只能取出test8.test1列,(第一列)
rs = (ResultSet)callable.getObject ( 2 );会出现无效的列索引的异常

请问是我的存储过程有问题,还是JSP代码有问题
如何解决,我想要取出test8表的所有列(test8.test1,test8.test2)
谢谢

...全文
121 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
vcdll 2003-05-21
  • 打赏
  • 举报
回复
谢谢,在sqlplus里面已经可以看到结果了

可对于jsp又该如何解决呢
jiezhi 2003-05-21
  • 打赏
  • 举报
回复
在sqlplus:
set serveroutput on;
exec pro(...);
w_tsinghua 2003-05-21
  • 打赏
  • 举报
回复
set serveroutput on;

declare
out_rs jutiPackage.test;
begin
out_rs := jutiPackage.get('y');

FOR test_rec IN out_rs LOOP
dbms_output.put_line(test_rec.test1);
dbms_output.put_line(test_rec.test2);
END LOOP;
end;
/

bzszp 2003-05-21
  • 打赏
  • 举报
回复
先执行
set serveroutput on;
...
vcdll 2003-05-21
  • 打赏
  • 举报
回复
谢谢大家,其实我最初也是用 rs = (ResultSet)callable.getObject(1);
rs.getInt(1);
rs.getInt(2);

可是不知道是什么原因只能显示第一列,于是才有上面一问,刚才试了一下竟然又好了
w_tsinghua 2003-05-21
  • 打赏
  • 举报
回复
rs = (ResultSet)callable.getObject(1);得到的是包含了test8.test1,test8.test2集合
正如Lastdrop(空杯) 说的要访问test8.test2,就应该用:
rs.getInt(2))
Lastdrop 2003-05-21
  • 打赏
  • 举报
回复
第二列不应该用
rs = (ResultSet)callable.getObject ( 2 )
而是应该用
out.println(rs.getInt(2));

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧