Oracle存储过程:JavaEye有BUG,贴不出PL/SQL代码,只好贴图片了!!!
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());
- }