2014-10-29 71 views
0

我有一個需求,那就是oracle過程向我發送一個oracle集合。這個集合包含clob數據類型。
我如何得到這個clob數據?如何從oracle集合中檢索clob數據

代碼:

public static void main(String[] args) throws SQLException { 
      DBLayer db=new DBLayer(); 
      CallableStatement ftRPCaStmt = null; 
      ResultSet requestPropCursor = null; 
      CallableStatement callsmt=null; 
      String dataCol="stg_core.tab_inft_flexi_gl_rec_hd2"; 
      Connection conn=db.getConnection(); 
    ArrayDescriptor structDescriptor1 = ArrayDescriptor.createDescriptor (dataCol.toUpperCase(), conn);     
        ftRPCaStmt = conn.prepareCall("{ call stg_core.gl_test1_clob_c2(?,?,?) }"); 
      ftRPCaStmt.registerOutParameter(1, Types.VARCHAR); 
      ftRPCaStmt.registerOutParameter(2, Types.VARCHAR); 
      ftRPCaStmt.registerOutParameter(3, Types.ARRAY,dataCol.toUpperCase()); 
      ftRPCaStmt.execute(); 

      Object[] data = (Object[]) ((Array) ftRPCaStmt.getObject(3)).getArray();  

當我印我得到的數據值作爲Ljava.lang.Object;@b2fd8f數據,但我需要CLOB數據..
請建議..

回答

1

嘗試爲

callsmt.registerOutParameter(3, OracleTypes.CLOB);

然後

Clob clob = proc_stmt.getClob(3); 
Reader reader = clob .getCharacterStream(); 
      char[] buffer = new char[1]; 
      while(reader.read(buffer) > 0) { 
       log.info(buffer); 
      }   
//   log.info(retValue); 
      .... 

上面的代碼片段沒有編譯,這是提供指導。

+0

@polpan在線程「main」中嘗試了您的suggestion.Exception異常時出現以下錯誤:java.sql.SQLException:ORA-06550:第1行第7列: PLS-00306:錯誤的調用參數數量或類型到'GL_TEST1_CLOB_C2' ORA-06550:第1行,第7列: PL/SQL:語句被忽略 – user2500313 2014-10-29 08:52:07

+0

@ user2500313通過編輯您的問題來添加'stg_core.gl_test1_clob_c2'函數的簽名。 – user75ponic 2014-10-29 09:21:22