2017-08-24 1 views
0

Je suis une erreur face à weblogic:weblogic.jdbc.wrapper.Array_oracle_sql_ARRAY ne peut pas être jeté à 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)

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

Il est bon de poster des messages et le code d'erreur, si vous avez une idée de ce qu'il pourrait être, il est bon à poster ça aussi. –

Répondre

0

Parfois, la connexion est renvoyée en tant que wrapper autour de la connexion native et vous devez déballer:

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

Ou, selon this answer, vous pouvez obtenir le non jacents déclaration appelable (et non une déclaration enveloppée):

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

Une autre solution possible serait de ne pas utiliser des variables intermédiaires et il suffit de faire:

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

Mise à jour:

Basé sur this answer vous pouvez également essayer:

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

Aucun de ceux-ci a travaillé dans mon cas. face à toujours la même erreur: weblogic.jdbc.wrapper.Array_oracle_sql_ARRAY ne peut pas être jeté à oracle.sql.ARRAY – tomi

0

La question se est résolu en ajoutant le code ci-dessous:

  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 
     } 

    } 

Vous pouvez vérifier ce lien: http://adfpractice-fedor.blogspot.com/2011/09/weblogic-wrapping-data-types.html