写入 方法
String inTime = new Timestamp(System.currentTimeMillis()).toString();
String sql = "INSERT INTO LWC.TAB_USER_SAY (ID_USER_SAY, MESSAGE_TITLE, MESSAGE_CONTENT, MSSSAGE_NAME, MSSSAGE_TEL, MESSAGE_EMAIL,MESSAGE_ADDRESS, MESSAGE_ZIP, OK_FLAG, IN_TIME) VALUES (LWC.SEQ_USER_SAY.NEXTVAL,'" +
DBUtil.FormatSQLValue(userSayForm.getMessageTitle()) + "',empty_clob(),'" + DBUtil.FormatSQLValue(userSayForm.getMessageName()) + "','" +
DBUtil.FormatSQLValue(userSayForm.getMessageTel()) + "','" + DBUtil.FormatSQLValue(userSayForm.getMessageEmail())+ "','" +
DBUtil.FormatSQLValue(userSayForm.getMessageAddress()) +"','" +
DBUtil.FormatSQLValue(userSayForm.getMessageZip()) +
"','0','" + inTime + "')";
logger.info(sql);
//提交Clob字段内容
//'" + DBUtil.FormatSQLValue(userSayForm.getMessageContent()) + "',
conn.setAutoCommit(false);
stat.executeUpdate(sql);
String sqll="select MESSAGE_CONTENT from LWC.TAB_USER_SAY where IN_TIME='"+inTime+"' for update";
ResultSet rss=stat.executeQuery(sqll);
if(rss.next()){
oracle.sql.CLOB clob = ((oracle.jdbc.OracleResultSet)rss).getCLOB(1);
clob.putString(1,DBUtil.FormatSQLValue(userSayForm.getMessageContent()));
sql="update LWC.TAB_USER_SAY set MESSAGE_CONTENT=? where IN_TIME='"+inTime+"'";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setClob(1,clob);
pstmt.executeUpdate();
pstmt.close();
}
conn.commit();
stat.close();
conn.close();
补充一句
如果是update 则应将原数据库中的 clob字段 update 成为 empty_clob()
然后通过 读取到 rs的 clob 中之后 再 update 新的内容
读取方法
//读取大文本
String content = "";
oracle.sql.CLOB x = ( (oracle.jdbc.driver.OracleResultSet) result).getCLOB("ORG_INTRO");
if (x != null) {
Reader is = x.getCharacterStream();
BufferedReader br = new BufferedReader(is);
String s = br.readLine();
while (s != null) {
content += s + "/r/n";
s = br.readLine();
}
}
可参考的几个WEB
http://blog.csdn.net/etre/archive/2003/07/20/17560.aspx
http://www.newer.com.cn/newer/bbs/topic.asp?topic_id=5270&cat_id=11&forum_id=19