java怎样创建一个blob对象
2个回答
展开全部
java向oracle写入blob
public void doWriteInHis(String id, String XML) {
int flag = 0;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rest = null;
StringBuffer insql = new StringBuffer();
insql.append("insert into test (id,IN_XML) ");
insql.append("values(?,empty_clob()) ");
StringBuffer sqlSelect = new StringBuffer();
sqlSelect.append("SELECT IN_XML FROM test ");
sqlSelect.append(" WHERE id = ? for update");
try {
conn = getConnection();
pstmt = conn.prepareStatement(insql.toString());
int index = 1;
pstmt.setString(index++, id);
flag = pstmt.executeUpdate();
pstmt.close();
if (flag > 0) {
pstmt = conn.prepareStatement(sqlSelect.toString());
index = 1;
pstmt.setString(index++, seq);
conn.setAutoCommit(false);
rest = pstmt.executeQuery();
if (rest.next()) {
oracle.sql.CLOB clob = (oracle.sql.CLOB) rest.getClob(1);
Writer os = clob.getCharacterOutputStream();
os.write(XML);
os.flush();
os.close();
}
conn.commit();
conn.setAutoCommit(true);
}
} catch (Exception e) {
SysLog.writeLogs("WriteHisDAOImpl", GlobalParameters.ERROR,
"WriteHisDAOImpl--doWriteInHis()-2:" + e.getMessage());
} finally {
close(conn);
}
}
2014-02-13
展开全部
楼上已写,可用先插入空的数据在修改的方式
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询