如何调用有返回有返回记录集的oracle的存储过程(100分)

  • 主题发起人 主题发起人 zhjwjan
  • 开始时间 开始时间
Z

zhjwjan

Unregistered / Unconfirmed
GUEST, unregistred user!
现在我会用callableStatement来执行简单的存储过程了,但如果存储过程是返回一个记录集的,
特别是oralce的存储过程,我就不知道该怎样传参数调用这个存储过程了,请问如何调用有返回
记录集的oracle的存储过程? 如何获得返回的记录集?谢谢!
 
looking help of oracle
 
摘自:bea/docs61/oracle/advanced.html
In your Java code, you'll construct CallableStatements with the stored procedures and register the output parameter as data type java.sql.Types.OTHER. When you retrieve the data into a ResultSet, use the output parameter index as an argument for the getResultSet() method.
weblogic.jdbc.oci.CallableStatement cstmt =
(weblogic.jdbc.oci.CallableStatement)conn.prepareCall(
"begin
OPEN ? " +
"FOR select * from emp;
end;
");
cstmt.registerOutParameter(1, java.sql.Types.OTHER);
cstmt.execute();
ResultSet rs = cstmt.getResultSet(1);
printResultSet(rs);
rs.close();
cstmt.close();
weblogic.jdbc.oci.CallableStatement cstmt2 =
(weblogic.jdbc.oci.CallableStatement)conn.prepareCall(
"begin
single_cursor(?, ?);
end;
");
cstmt2.registerOutParameter(1, java.sql.Types.OTHER);
cstmt2.setInt(2, 1);

cstmt2.execute();
rs = cstmt2.getResultSet(1);
printResultSet(rs);

cstmt2.setInt(2, 2);

cstmt2.execute();
rs = cstmt2.getResultSet(1);}
printResultSet(rs);
cstmt2.setInt(2, 3);

cstmt2.execute();
rs = cstmt2.getResultSet(1);
printResultSet(rs);
cstmt2.close();
weblogic.jdbc.oci.CallableStatement cstmt3 =
(weblogic.jdbc.oci.CallableStatement)conn.prepareCall(
"begin
multi_cursor(?, ?, ?);
end;
");
cstmt3.registerOutParameter(1, java.sql.Types.OTHER);
cstmt3.registerOutParameter(2, java.sql.Types.OTHER);
cstmt3.registerOutParameter(3, java.sql.Types.OTHER);
cstmt3.execute();
ResultSet rs1 = cstmt3.getResultSet(1);
ResultSet rs2 = cstmt3.getResultSet(2);
ResultSet rs3 = cstmt3.getResultSet(3);
 
//这是我的项目里的一个应用!
Tstor.StoredProcName := 'PROC_SJCJ';
Tstor.Params.Clear;
Tstor.Params.CreateParam(ftinteger, 'param1', ptInput);
Tstor.Params.CreateParam(ftinteger, 'param2', ptInput);
Tstor.Params.CreateParam(ftString, 'param3', ptInput);
Tstor.Params.CreateParam(ftString, 'param4', ptInput);
Tstor.Params.CreateParam(ftString, 'param5', ptoutput);
Params.Items[0].Value := 1;
Params.Items[1].Value := 1;
Params.Items[2].Value := '20020202';
Params.Items[3].Value := '000731';
Synchronize(execproc);
astr := Params.Items[4].Value;
//不好意思看错了^_^
 
to papa, 你的办法是用weblogic.jdbc.oci.CallableStatement,但我的jbuilder里用的是
java.sql.CallableStatement,我的参数类型设为OTHER,但执行时仍然说invalid column type,
这是怎么回事?谢谢你回答我的问题!
 
我找到答案了,
cstmt.registerOutParameter(1,oracle.jdbc.driver.OracleTypes.CURSOR);
http://developer.novell.com/ndk/doc/samplecode/jdbc_sample/oci7/RefCursorExample.java.html
 
来学习的,顺便混点分.
 
多人接受答案了。
 

Similar threads

回复
0
查看
978
不得闲
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
900
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部