【问题标题】:weblogic.jdbc.wrapper.Array_oracle_sql_ARRAY cannot be cast to oracle.sql.ARRAYweblogic.jdbc.wrapper.Array_oracle_sql_ARRAY 不能强制转换为 oracle.sql.ARRAY
【发布时间】:2019-05-24 02:08:34
【问题描述】:

我在 weblogic 中面临错误:

java.lang.ClassCastException:weblogic.jdbc.wrapper.Array_oracle_sql_ARRAY 无法在 weblogic.jdbc.wrapper.CallableStatement_oracle_jdbc_driver_OracleCallableStatementWrapper.getARRAY(未知来源)中转换为 oracle.sql.ARRAY

代码:

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

【问题讨论】:

  • 最好发布错误消息和代码,如果您有任何想法,也可以发布。

标签: java oracle jdbc weblogic12c classcastexception


【解决方案1】:

数据源中的一个简单参数更改应该可以使其工作。

转到数据源 -> 选择数据源 -> 配置 -> 连接池 -> 高级,然后取消选中“包装数据类型”。

这应该可以解决问题。

【讨论】:

    【解决方案2】:

    有时连接会作为原生连接的包装返回,您需要解开它:

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

    或者,根据this answer,您可以获得底层可调用语句(而不是包装语句):

    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);
    

    【讨论】:

    • 这些都不适用于我的情况。仍然面临同样的错误:weblogic.jdbc.wrapper.Array_oracle_sql_ARRAY 无法转换为 oracle.sql.ARRAY
    【解决方案3】:

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

               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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-03
      • 2019-06-09
      • 2017-06-02
      • 2013-07-21
      • 2016-09-26
      • 1970-01-01
      • 2013-03-20
      • 2020-12-06
      相关资源
      最近更新 更多