[英]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.