我有一个程序从文件中读取xml并更新clob。看起来这个程序在clob的末尾添加了额外的字符,有人可以让我知道缺少什么。
public class UpdateClob {
@SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception {
{
FileInputStream ifs = null;
OutputStream COS = null;
String sqlText1 = null;
Statement stmt = null;
ResultSet rset = null;
CLOB xmlDocument = null;
int bufferSize;
byte[] byteBuffer;
int bytesRead = 0;
int totBytesRead = 0;
int totBytesWritten = 0;
Connection conn = null;
File input = null;
conn=getConnection();
stmt = conn.createStatement();
Clob myClob = conn.createClob();
input = new File("C:\Test.xml");
ifs = new FileInputStream(input);
sqlText1 = "SELECT xml_doc FROM table_name FOR UPDATE";
rset = stmt.executeQuery(sqlText1);
rset.next();
xmlDocument = ((OracleResultSet) rset).getCLOB("xml_doc");
bufferSize = xmlDocument.getBufferSize();
byteBuffer = new byte[bufferSize];
COS= xmlDocument.getAsciiOutputStream();
while ((bytesRead = ifs.read(byteBuffer)) != -1) {
COS.write(byteBuffer, 0, bytesRead);
totBytesRead += bytesRead;
totBytesWritten += bytesRead;
}
ifs.close();
COS.close();
conn.commit();
rset.close();
stmt.close();
}}