//String sqlsel2 = "select jsonbody from db_ps_listcatalog where" +
//" listtype ='sh11' for update";
// String col="jsonbody";
public boolean updateClob(String sql,String col,String buf){
boolean flag=false;
Statement stem=null;
Connection conn=null;
ResultSet rs=null;
Writer wr = null;
try{
conn= dp.getConnection();
conn.setAutoCommit(false);
stem=conn.createStatement();
rs = stem.executeQuery(sql);
if (rs.next()) {
CLOB clob = (CLOB) rs.getClob(col);
java.lang.reflect.Method methodToInvoke = clob.getClass().getMethod(
"getCharacterOutputStream", (Class[]) null);
wr = (Writer) methodToInvoke.invoke(clob, (Object[]) null);
BufferedWriter bw = new BufferedWriter(wr);
bw.write(buf);
bw.flush();
bw.close();
conn.commit();
conn.close();
}
flag=true;
} catch (Exception ex){
try {
conn.rollback();
} catch (SQLException e) {
e.printStackTrace();
}
}
return flag;
}
这段代码展示了一个更新CLOB类型字段的方法,通过SQL查询获取指定listtype的数据,然后使用反射调用CLOB对象的方法写入内容,并进行事务提交。该过程涉及到数据库连接、事务控制和CLOB对象的操作。

1979

被折叠的 条评论
为什么被折叠?



