·創建存儲過程
create or replace procedure myDemo03(total out int,name out sys_refcursor)
as begin
select count(1) into total from bizsys;
open name for select * from bizsys;
end myDemo03;
oracle 創建存儲過程及通過jdbc調用
/**
* jdbc執行存儲過程
* @Description: callProcedure(conn, "call myDemo03(total=>:total,name=>:name)");
* @Creator: lx
* @CreateTime: 2019年9月16日 上午11:47:22
* @Modifier:
* @ModifyTime:
* @Reasons:
* @param conn
* @param exec
* @throws Exception
*/
public static boolean callProcedure(Connection conn,String sql) throws Exception {
CallableStatement cs = null;
sql="{"+sql+"}";
try {
cs = conn.prepareCall(sql);
cs.registerOutParameter("total", OracleTypes.VARCHAR);
cs.registerOutParameter("name", OracleTypes.CURSOR);
cs.execute();
Object rs = cs.getObject("total");
ResultSet resultSet = (ResultSet)cs.getObject("name");
System.out.println(rs);
while (resultSet.next()) {
Object o=resultSet.getObject("name");
System.out.println(o);
}
} catch (Exception e) {
e.printStackTrace();
throw new Exception("執行存儲過程異常");
}finally{
cs.close();
close(conn);
}
return true;
}