Fetching Data from PL-SQL Table as OUT parameter in Java
I am executing a procedure from java code, which has 2 out parameters, One of those is a Object table. here is the overview of pac开发者_StackOverflow中文版kage
PROCEDURE SalesProc (
p_S_table IN t_s_table
, p_T_table IN OUT t_t_table
, x_message OUT VARCHAR2
)
t_table is IN OUT parameter which contains several String and Numbers into it. Before executing the package I am creatng an SalesObject array and setting into it.
Here, the aim is to get some value from t_table using resultSet.
the source I am trying to get working is:
callstmt.registerOutParameter(2, Types.ARRAY,"T_TABLE");
callstmt.setArray(2, mySalesObjectArray);
callstmt.execute();
java.sql.Array aa = callstmt.getArray(2);
ResultSet rs = aa.getResultSet();
while(rs.next()){
String ss = rs.getString(1);
}
Following line is giving "java.sql.exception
"
String ss = rs.getString(1);
I am also trying to cast it into Object type as follows
salesObject[] sArray = (salesObject[])callstmt.getArray(2);
Which is throwing classCastException.
"classcastException.Cannot cast java.lang.Object[2][id=16062] to java.lang.String[]
"
how can I avoid these exceptions?
You have 3 parameters, the counting starts from 1 from the left most parameter:
- p_S_table
- p_T_table
- t_t_table
I use Oracle as a DBMS but haven't use IN/OUT parameters but I'm sure that if u change youre procedure into a function (because a function returns something) that takes the IN parameters and returns the OUT one, same code will work.
As for the casting here:
salesObject[] sArray = (salesObject[])callstmt.getArray(2);
your salesObject
class should implement either ORAData
or SQLData
.
SQLData
seems nicer.
精彩评论