简体   繁体   中英

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

I have an xml file, from which I need to get the element information into a clob column in oracle table. the xml file is like this:

<?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>

The notepad element information has to go into clob column in the oracle tableand the documents element information had to go into blob column in the same table.

Code written is as follows:

    **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();
        }       
    }

This approach of loading String data into clob column in oracle table works perfectly. But the Byte[] data is not loading into the blob column in oracle table?

Pls see the changed code and advise me. Thank You Sir.

Try the below code

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

or try this

these two BLOB are not compatible you can try

 weblogic.jdbc.common.OracleBlob

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM