Reputation: 7889
I'm writing some JDBC code which calls a Oracle 11g PL/SQL procdedure which has a Custom Object return type. I can get the code to call the procedure, but how do I access the returned Custom Object to obtain it's contained values?. An example of my code calling the procedure is below:
PLSQL Code:
Procedure GetDataSummary (p_my_key IN KEYS.MY_KEY%TYPE,
p_recordset OUT data_summary_tab,
p_status OUT VARCHAR2);
Java Code:
String query = "begin manageroleviewdata.getdatasummary(?, ?, ?); end;");
CallableStatement stmt = conn.prepareCall(query);
// Single IN parameter
stmt.setInt(1, 83);
// Two OUT parameters, one a Custom Object, the other a VARCHAR
stmt.registerOutParameter(2, OracleTypes.ARRAY, "DATA_SUMMARY_TAB");
stmt.registerOutParameter(3, OracleTypes.VARCHAR);
stmt.execute(stmt);
How do I get the result back fron this?
Upvotes: 0
Views: 1859
Reputation: 7889
We've cracked it:
oracle.sql.ARRAY result2 = (oracle.sql.ARRAY) stmt.getObject(2);
ResultSet rs = result2.getResultSet();
oracle.sql.STRUCT elements = (oracle.sql.STRUCT) rs.getObject(2);
String result = null;
if (elements != null) {
Object[] objs = elements.getAttributes();
result = objs[2];
}
System.out.println("Result: " + result);
In our case this prints the third element in our Custom Object type.
Upvotes: 1