java 处理oracle 存储过程返回的cursor

    xiaoxiao2023-03-24  4

    package com.lance.util; import java.sql.*; import oracle.jdbc.OracleTypes; public class QueryProc { public void callOracleStoredProcCURSORParameter() throws SQLException { Connection dbConnection = null; CallableStatement callableStatement = null; ResultSet rs = null; String getTRACKED_PROC = "{call TRACKED_PROC(?,?)}"; try { dbConnection =  OracleDbUtil.init(); callableStatement = dbConnection.prepareCall(getTRACKED_PROC); callableStatement.setString(1, "mkyong"); callableStatement.registerOutParameter(2, OracleTypes.CURSOR); // callableStatement.registerOutParameter(1, OracleTypes.CURSOR); // execute getDBUSERCursor store procedure callableStatement.executeUpdate(); // get cursor and cast it to ResultSet rs = (ResultSet) callableStatement.getObject(2); while (rs.next()) { String userid = rs.getString("No"); String userName = rs.getString("tobj_status_key"); String createdBy = rs.getString("tobj_type"); String createdDate = rs.getString("status"); System.out.println("No : " + userid); System.out.println("tobj_status_key : " + userName); System.out.println("tobj_type : " + createdBy); System.out.println("status : " + createdDate); } System.out.println("nothing"); } catch (SQLException e) { System.out.println(e.getMessage()); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (rs != null) { rs.close(); } if (callableStatement != null) { callableStatement.close(); } if (dbConnection != null) { dbConnection.close(); } } } }
    转载请注明原文地址: https://ju.6miu.com/read-1202455.html
    最新回复(0)