i am calling a stored procedure from java and as an out parameter i am giving a struct
. Every thing works fine with below code;
conn = DriverManager.getConnection(URL,"username","password")
StructDescriptor recDescriptor = StructDescriptor.createDescriptor("TCS_CHALLAN",conn);
CallableStatement stmt = conn.prepareCall("{ call xx_get_challan_info(?, ?) }");
Object[] return_record_array = new Object[8];
STRUCT output_oracle_record;
stmt.setObject(1, challan_no);
stmt.registerOutParameter(2, OracleTypes.STRUCT, "TCS_CHALLAN");
output_oracle_record = ((OracleCallableStatement)stmt).getSTRUCT(2);
return_record_array = output_oracle_record.getAttributes();
The problem occurs when i get my connection from a datasource
at weblogic server
.
javax.naming.Context initialContext = new javax.naming.InitialContext();
javax.sql.DataSource dataSource = (javax.sql.DataSource)initialContext.lookup("jdbc/testApps");
conn = dataSource.getConnection();
With above conn
object when i try the same code i get an error
weblogic.jdbc.wrapper.Struct_oracle_sql_STRUCT cannot be cast to oracle.sql.STRUCT
So this was the solution.When running your code in weblogic you need to do some extra casting. make sure to include jar files in your classpath.
/*Code to support Weblogic datatypes*/
Object returnObj = stmt.getObject(2);
if (returnObj instanceof Struct)
output_oracle_record = (oracle.sql.STRUCT)(((weblogic.jdbc.wrapper.Struct)returnObj).unwrap(Class.forName("oracle.sql.STRUCT")));
else
output_oracle_record = (oracle.sql.STRUCT)returnObj;
/*code for tomcat deployment*/
//output_oracle_record = ((OracleCallableStatement)stmt).getSTRUCT(2);