日期:2014-05-16 浏览次数:20534 次
新建存储过程
create or replace procedure getcur(p_rc out sys_refcursor) is begin open p_rc for 'select * from room'; end getcur;
?java中调用
Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@host:port:databasename", "user", "pwd"); // DriverManager.registerDriver (new oracle.jdbc.OracleDriver()); CallableStatement callsta = null; ResultSet rs = null; try { callsta = conn.prepareCall("{call getcur(?)}"); callsta.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR); callsta.execute(); rs = (ResultSet) callsta.getObject(1); while (rs.next()) { System.out.println(rs.getString(1)+rs.getString(2)); } rs.close(); callsta.close(); conn.close(); } catch (Exception e) { e.printStackTrace(); }?