大侠们 我想问一下,我有一个存储过程有一个输入参数和2个输出参数,一个输出参数是返回一个vachar一个是返回一个集类型,我想问怎么写存储过程,最主要是的在程序中怎么调用,详细贴一下代码,并给我讲解一下,谢谢了。要全代码哦 我有点菜
解决方案 »
- 求解 求答案 为什么不能调用DB中name 和 word两个属性
- 怎么样才能把JAVA学好???
- 怎样使用Struts1.x中的令牌(Token)避免注册时重复刷新插入值的问题?
- 小弟请教各位大虾一个问题
- java中set函数(姑且先这么叫吧)和get的用法
- 提交的时候URL中.action后缀没了
- weblogic 对同一个工程如何发布两次!!??????
- 这是mysql还是hibernate的bug?还是其它?
- 关于记录日志的超难度问题,相信只有超牛人才能回答了。
- 急问高手一个问题
- 关于java事务的问题!
- hibernate问题:The content of element type "class" must match The content of ele..
首先,建立存储过程( 建立student表略 ):
create or replace procedure p_student_info(i_sex in varchar2,o_cur out sys_refcursor)
is
begin
open o_cur for select * from student where student_sex=i_sex;
end;
存储过程既有in类型也有out类型且out类型是cursor。
java代码:
建立数据库链接省略,注意不要以system账号链接:
调用方法:
public static void cursorTest(){
Connection conn = JdbcUtil.getConnection();
CallableStatement cstmt = null;
try {
cstmt = conn.prepareCall("{call p_student_info(?,?)}");
cstmt.setString(1, "m");
cstmt.registerOutParameter(2, OracleTypes.CURSOR);//out类型需要注册
cstmt.execute();
ResultSet rs = (ResultSet)cstmt.getObject(2);//此处的2要与存储过程中cursor的问题对应
while(rs.next()){
System.out.println(rs.getString(1));//获取具体的值
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
调用以上方法测试。
is
begin
open o_cur for select * from student where student_sex=i_sex;
end;
is
begin
open o_cur for select * from student where student_sex=i_sex;
end;