Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
435 views
in Technique[技术] by (71.8m points)

java - Accessing the Custom Object Return type from ojdbc6 JDBC Thin Drivers

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...