使用jdbc连接数据库,插入和读取clob字段都没有问题,可是在读取后编辑,如果编辑后内容小于编辑前,保存到数据库里就多出一截(有时就多出编辑前的内容);如果编辑后多于编辑前就没有问题,不知道怎么回事?比如编辑前是“1234567890”,编辑后变成“12345”,但是保存了数据库里还是“1234567890”?
编辑保存的代码如下:
Cn cn = new Cn(request);

String sql="update ress_faultcase set topic='"+ topic +"', author= '"+ fullname + "',author_id= '"+ authorid +"', edittime= '" + sqltime + "' where file_id='"+file_id+"' ";
cn.executeUpdate(sql); 
cn.conn.setAutoCommit(false);
sql = "select content from ress_faultcase where file_id='"+file_id+"' for update";
ResultSet rs=cn.executeQuery(sql);
if (rs.next()) {
  oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob(1);
  clob.putString(1, content);
  sql = "update ress_faultcase set content=? where file_id='" + file_id + "'";                    PreparedStatement pstmt = cn.conn.prepareStatement(sql);
  pstmt.setClob(1, clob);
  pstmt.executeUpdate();
}
rs.close();
cn.close();