从ojdbc6 JDBC瘦驱动程序访问定制对象返回类型 [英] Accessing the Custom Object Return type from ojdbc6 JDBC Thin Drivers
本文介绍了从ojdbc6 JDBC瘦驱动程序访问定制对象返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一些JDBC代码,该代码调用具有Custom Object返回类型的Oracle 11g PL/SQL过程.我可以获取调用该过程的代码,但是如何访问返回的自定义对象以获得其包含的值?我的代码调用该过程的示例如下:
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代码:
Procedure GetDataSummary (p_my_key IN KEYS.MY_KEY%TYPE,
p_recordset OUT data_summary_tab,
p_status OUT VARCHAR2);
Java代码:
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);
如何从此获得结果?
推荐答案
我们已将其破解:
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.
这篇关于从ojdbc6 JDBC瘦驱动程序访问定制对象返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文