0

I am an facing error in weblogic:

java.lang.ClassCastException: weblogic.jdbc.wrapper.Array_oracle_sql_ARRAY cannot be cast to oracle.sql.ARRAY at weblogic.jdbc.wrapper.CallableStatement_oracle_jdbc_driver_OracleCallableStatementWrapper.getARRAY(Unknown Source)

Code:

   public String[] methodName(String[] P1,String P2,String P3,String P4, String P5,int Sessioninfo)
{
    Connection conn = null;
    CallableStatement cstmt = null;
    ResultSet rs = null;
    String[] returnArray = null;

    try {
        ds=getDataSource(Sessioninfo);
        conn = ds.getConnection();
        conn = new CommonsDbcpNativeJdbcExtractor().getNativeConnection(conn);
        conn.setAutoCommit(false);

        ArrayDescriptor oracleVarchar2Collection =
                ArrayDescriptor.createDescriptor("VARRAY_PARTS",conn);
        ARRAY sqlNos = new ARRAY(oracleVarchar2Collection, conn, P1);

        cstmt =conn.prepareCall("{call Procedure1(?,?,?,?,?,?)}");
        cstmt.setObject(1, sqlNos);
        cstmt.setString(2, P2);
        cstmt.setString(3, WebpartsUtility.convertSQLStringIN(P3,","));
        cstmt.setString(4, WebpartsUtility.convertSQLStringIN(P4,","));
        cstmt.setString(5,P5);

        cstmt.registerOutParameter(6,OracleTypes.ARRAY, "VARRAY_PARTS");

        cstmt.setFetchSize(2500);
        cstmt.execute();
        ARRAY mainArray = ((OracleCallableStatement)cstmt).getARRAY(6);
        returnArray = (String[]) mainArray.getArray();

    } catch (SQLException ex) {
        logger.fatalMsg("Sql Exception Occured :: "+ex.getMessage(),ex);
    } catch (Exception ex) {
        logger.fatalMsg("Exception Occured :: "+ex.getMessage(),ex);
    } finally {
        try {
            if (cstmt != null) {
                cstmt.close();
                cstmt = null;
            }                       
            if (conn != null) {
                conn.close();
                conn = null;
            }
            if (ds != null) {
                ds = null;
            }
        } catch (SQLException ex) {
            logger.fatalMsg("Sql Exception Occured :: "+ex.getMessage(),ex);
        } catch (Exception ex) {
            logger.fatalMsg("Exception Occured :: "+ex.getMessage(),ex);
        }
    }

    return returnArray;
}
1
  • It's good to post error messages and code, if you have any idea as to what it could be, it's good to post that too. Commented Aug 24, 2017 at 14:07

3 Answers 3

3

A simple parameter change in the datasource should make it work.

Go to datasource -> select the datasource -> Configuration -> Connection Pool -> Advanced then uncheck "Wrap Data Types".

This should resolve the issue.

Sign up to request clarification or add additional context in comments.

Comments

1

Sometimes the connection is returned as a wrapper around the native connection and you need to unwrap it:

conn = new CommonsDbcpNativeJdbcExtractor().getNativeConnection(conn);
OracleConnection oConn;
if ( conn.isWrapperFor( OracleConnection.class ) )
{
  oConn = (OracleConnection) conn.unwrap( OracleConnection.class );
}
else
{
  oConn = (OracleConnection) conn;
}

Or, as per this answer, you could get the underlying callable statement (and not a wrapped statement):

OracleCallableStatement cstmt
    = (OracleCallableStatement) conn.prepareCall("{call Procedure1(?,?,?,?,?,?)}")
                                    .getUnderlyingStatement();

Another potential solution would be to not use intermediate variables and just do:

returnArray = (String[]) ((OracleCallableStatement)cstmt).getARRAY(6).getArray();

Update:

Based on this answer you could also try:

ARRAY mainArray = (ARRAY) ((weblogic.jdbc.wrapper.Array) (callableStmt).getObject(3))
                              .unwrap(ARRAY.class);

1 Comment

None of these worked in my case. Still facing the same error: weblogic.jdbc.wrapper.Array_oracle_sql_ARRAY cannot be cast to oracle.sql.ARRAY
1

The issue got resolved adding the below code:

           try {
        statement.setLong(1, new Long(1));
        statement.registerOutParameter(2, Types.ARRAY, "TNUMBERTABLE");
        statement.execute();
        ARRAY ar = null;
        Object someArray = statement.getArray(2);
        if (someArray instanceof weblogic.jdbc.wrapper.Array)
            ar =
      (oracle.sql.ARRAY(((weblogic.jdbc.wrapper.Array)someArray).unwrap(Class.forName("oracle.sql.ARRAY")));
        else
            ar = (oracle.sql.ARRAY)someArray;

        for (long i : ar.getLongArray()) {
            //code if needed
        }

    } 

You can check this link:http://adfpractice-fedor.blogspot.com/2011/09/weblogic-wrapping-data-types.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.