簡體   English   中英

從XMl文件中,需要將xml元素數據放入oracle表的clob列中

[英]From an XMl file, an xml element data needs to be put into a clob column in oracle table

我有一個xml文件,需要從中獲取元素信息到oracle表的clob列中。 xml文件是這樣的:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<bookstore>
  <notepad>
   Test Notepad data. Test Notepad data. 
  </notepad>
  <documents>
   werfjkhrgkhrekgjeirogvmj vreuhfgiurvhe kjhr ieu
   ndbcjhaejvh ukarehv khrkuehgvuhwrhuivg hrfjkhuirehv
  </documents>
</bookstore>

記事本元素信息必須進入oracle表的clob列,而documents元素信息必須進入同一表的blob列。

編寫的代碼如下:

    **String notes = report.getNotepadInfo();
    System.out.println("the notes is : "+notes);**

    byte[] documentValByteArr = report.getDocumentsList().get(0).getDocumentValues().get(0).getDocumentValue().getBytes();                          
    System.out.println("documentValByteArr :"+documentValByteArr);

    //Pass the String notes to load as clob and Pass the byte[] to load as blob to LoadData class's updateDV method to update in the database.
    LoadData.updateDV(id,documentValByteArr,notes);

    enter code here 

    public static void updateDCNVersion(String Id, byte[] blob, String clob) {
      **ByteArrayInputStream bais = new ByteArrayInputStream(blob);**

        // Here we run the Function to update data in the table.
        try {
            CallableStatement proc_stmt = connection.prepareCall(" {call P_UPDATE_DV(?,?,?)}");
            proc_stmt.setString(1,Id);
                     proc_stmt.setBinaryStream(2, bais, (int)blob.length);
        proc_stmt.setString(3, clob);
                proc_stmt.executeQuery();
            proc_stmt.close();
        } catch (SQLException e) {
            System.out.println("ERROR: SQL Exception updating T_DV");
            System.err.println("SQLState: " + e.getSQLState());
            e.printStackTrace();
        }       
    }

這種將String數據加載到oracle表的clob列中的方法非常有效。 但是Byte []數據沒有加載到oracle表的blob列中嗎?

請查看更改后的代碼並提出建議。 謝謝你,先生。

試試下面的代碼

byte[] documentValByteArr = ..........    
ByteArrayInputStream bais = new ByteArrayInputStream(documentValByteArr );
pstmt.setBinaryStream(1, bais , (int)documentValByteArr .length());

或嘗試這個

這兩個BLOB不兼容,您可以嘗試

 weblogic.jdbc.common.OracleBlob

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM