public int addXmlTemp(Emr_cda_standard_ntDTO bean,InputData inputData) throws GeneralException{
logger.info(" addXmlTemp begin ......");
String data = bean.getContent();
Writer outStream = null;
int count = 0;
//通过JDBC获得数据库连接
try {
Connection con = this.getConnection();
con.setAutoCommit(false);
Statement st = con.createStatement();
//插入一个空对象empty_clob(),这个是必须的
st.executeUpdate("insert into xml_temp(ID, xml_content)values("+bean.getCode()+", empty_clob())");
//锁定数据行进行更新,注意“for update”语句,这里不用for update锁定不可以插入clob
ResultSet rs = st.executeQuery("select xml_content from xml_temp where id="+bean.getCode()+" for update");
if (rs.next())
{
//得到java.sql.Clob对象后强制转换为oracle.sql.CLOB
CLOB clob = (CLOB) rs.getClob("XML_CONTENT");
outStream = clob.getCharacterOutputStream();
//data是传入的字符串,定义:String data
char[] c = data.toCharArray();
outStream.write(c, 0, c.length);
}
outStream.flush();
outStream.close();
con.commit();
con.close();
count = 1;
} catch (Exception e) {
e.printStackTrace();
}
logger.info(" addXmlTemp end ......");
return count;
}
参考自:http://www.linuxidc.com/Linux/2013-06/86381.htm