2017-08-24 73 views
0

我在weblogic的面向错误:weblogic.jdbc.wrapper.Array_oracle_sql_ARRAY不能转换为oracle.sql.ARRAY

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)

代码:

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; 
} 
+0

这是很好的发布错误消息和代码,如果您有任何想法,可能是什么,它的很好也张贴。 –

回答

0

有时连接返回作为包装器本地连接,你需要解开它:

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

或者,按照this answer,你可以得到未derlying调用语句(而不是包装声明):

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

另一个潜在的解决办法是不使用中间变量,只是做:

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

更新

基于this answer你也可以尝试:

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

这些在我的情况下都不起作用。仍然面临相同的错误:weblogic.jdbc.wrapper.Array_oracle_sql_ARRAY无法转换为oracle.sql.ARRAY – tomi

0

的问题得到了解决添加以下代码:

  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 
     } 

    } 

您可以检查此链接:http://adfpractice-fedor.blogspot.com/2011/09/weblogic-wrapping-data-types.html

相关问题