怎样让 Oracle 的存储过程返回结果集
怎样让 oracle 的存储过程返回结果集?
Oracle 存储过程:
Java 调用代码:
try { DriverManager.registerDriver (new oracle.jdbc.OracleDriver()); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ora10g", "user", "user"); CallableStatement stmt = conn.prepareCall("BEGIN GETCITY(?, ?); END;"); //CallableStatement stmt = conn.prepareCall("{ call GETCITY(?, ?) }"); stmt.setString(1, "021"); stmt.registerOutParameter(2, -10 /* OracleTypes.CURSOR = -10 */); //REF CURSOR(OracleTypes.CURSOR==-10) stmt.execute(); ResultSet rs = (ResultSet) stmt.getObject(2); while (rs.next()) { System.out.println(rs.getString("CITY_NAME")); } rs.close(); rs = null; stmt.close(); stmt = null; conn.close(); conn = null; } catch (SQLException e) { System.out.println(e.getLocalizedMessage()); }
原文链接:http://wjw465150.javaeye.com/blog/396071。