日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

存clob为空的值_将网页文本(HTML)保存到ORACLE数据库CLOB字详解

發布時間:2023/11/27 生活经验 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 存clob为空的值_将网页文本(HTML)保存到ORACLE数据库CLOB字详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

網上常見的例子總是將文本文件上傳至數據庫的方法。今天在做文檔管理相關系統時,需要將網頁上的文本輸入框(textarea或input)中的內容,上傳到ORACLE數據庫的CLOB字段中去。在網上找了好長時間,總算有所收獲,現將方法總結如下,其中部分代碼為其它網友的源碼:

一、上傳

private void updateContent(Connection conn, Information info) throws Exception {

PreparedStatement pstmt = conn.prepareStatement(

"SELECT CONTENT FROM INFO_CONTENT WHERE ID=? FOR UPDATE");

pstmt.setInt(1, info.getId());

ResultSet rs = pstmt.executeQuery();

/* 取出此CLOB對象 */

if (rs.next()) {

//Weblogic這樣寫

OracleThinClob clob = (OracleThinClob) rs.getClob(1);

//其它服務器這樣寫

//oracle.sql.CLOB clob = (oracle.sql.CLOB) rs.getClob(1);

/* 向CLOB對象中寫入數據 */

/*

//保存文件

//BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());

//BufferedReader in = new BufferedReader(new FileReader(filename));

*/

//保存字符串

Writer out = clob.getCharacterOutputStream();

out.write(info.getContent());

out.flush();

out.close();

rs.close();

pstmt.close();

}

}

二、在jsp中顯示

public Information getInformation(int id) throws Exception {

Information base = new Information();

Connection conn = null;

try {

conn = DBConnect.GainDBConnect();

PreparedStatement ps = conn.prepareStatement(

"SELECT * FROM INFO_CONTENT WHERE ID=?");

ps.setInt(1, id);

ResultSet rs = ps.executeQuery();

while (rs.next()) {

java.sql.Clob clob = (java.sql.Clob) rs.getClob("CONTENT");

/* 以字符形式輸出 */

Reader out = new BufferedReader(clob.getCharacterStream());

BufferedReader bfClob = new BufferedReader(out);

String strClob = bfClob.readLine();

StringBuffer sbResult = new StringBuffer();

while (strClob != null) {

sbResult.append(strClob);

strClob = bfClob.readLine();

}

base.setContent(sbResult.toString());

out.close();

}

rs.close();

ps.close();

}

catch (Exception ex) {

System.out.println(ex);

throw ex;

}finally {

conn.close();

}

return base;

}

轉載請注明來源網站:www.itxm.cn謝謝!

分享到:

總結

以上是生活随笔為你收集整理的存clob为空的值_将网页文本(HTML)保存到ORACLE数据库CLOB字详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。