【发布时间】:2015-05-12 14:23:26
【问题描述】:
我有一个 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列,文档元素信息必须进入同一张表的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();
}
}
这种将字符串数据加载到 oracle 表中的 clob 列的方法非常有效。 但是 Byte[] 数据没有加载到 oracle 表的 blob 列中?
请查看更改后的代码并告诉我。 谢谢楼主。
【问题讨论】:
标签: java