I'm deploying my application on Weblogic 10.3.6. And trying to connect Oracle database to call stored function and i'm using OracleCallableStatement and OracleTypes.STRUCT.
But i'm getting the below error:
java.lang.ClassCastException: weblogic.jdbc.wrapper.Struct_oracle_sql_STRUCT cannot be cast to oracle.sql.STRUCT
FIX:
import
java.sql.CallableStatement;
import java.sql.Types;
import
java.sql.Connection;
...
CallableStatement statement = null;
...
statement =
conn.prepareCall("{?=call YOUR_SHEMA.your_stored_function_name(?)}");
statement.registerOutParameter(1,
Types.STRUCT, "YOUR_SHEMA.your_return_object_name");
statement.setLong(2,
"your_input_parameter");
statement.execute();
Object
attributeList[] = ((java.sql.Struct)statement.getObject(1)).getAttributes();
if(attributeList != null) {
//examples
Timestamp date = (Timestamp)attributeList[6];
String text = attributeList[8].toString();
}
|
OR:
If you use weblogic extension version then you can use vendorConnection with OracleCallableStatement and OracleTypes.STRUCT.
import
java.sql.Connection;
import
weblogic.jdbc.extensions.WLConnection;
...
Connection con =
dataSource.getConnection();
oracle.jdbc.OracleConnection
conn2 = (oracle.jdbc.OracleConnection)(((WLConnection)con).getVendorConnection());
return conn2;
...
|
No comments:
Post a Comment