java程序如何调用oracle的plsql语句
1个回答
展开全部
一个简单的例子看看:
先建包:
create or replace package testpackage as
type test_cursor is ref cursor;
end testpackage;
建立存储过程:
create or replace procedure sp_pro(spNo in number,p_cursor out testpackage.test_cursor) is
begin
open p_cursor for select * from emp where deptno=spNo;
end;
java调用:
CallableStatement cs=ct.prepareCall("{call sp_pro(?,?)}");
cs.setInt(1,10);
cs.registerOutParameter(2,oracle.jdbc.OracleTypes.CURSOR);
cs.execute();
ResultSet rs=(ResultSet)cs.getObject(2);
while(){
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
先建包:
create or replace package testpackage as
type test_cursor is ref cursor;
end testpackage;
建立存储过程:
create or replace procedure sp_pro(spNo in number,p_cursor out testpackage.test_cursor) is
begin
open p_cursor for select * from emp where deptno=spNo;
end;
java调用:
CallableStatement cs=ct.prepareCall("{call sp_pro(?,?)}");
cs.setInt(1,10);
cs.registerOutParameter(2,oracle.jdbc.OracleTypes.CURSOR);
cs.execute();
ResultSet rs=(ResultSet)cs.getObject(2);
while(){
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询