`

EMPTY_CLOB() 在程序中的用法

    博客分类:
  • j2ee
阅读更多

转自网络:

在向带有Lob类型的字段加入数据时,使用EMPTY_CLOB()初始化CLOB字段,然后再使用输出流向字段中写数据(这些数据往往都是字节流量相对较大的). 如果是直接在oracle客户端向表中写数据,就不用这么麻烦了.

好了,具体的操作:

 

 

 

CREATE TABLE article(
    subject VARCHAR2(50 char),
    content CLOB ,
    tstamp TIMESTAMP DEFAULT SYSDATE 
);

--使用EMPTY_CLOB()来初始化CLOB字段
String strSql = "INSERT INTO article(subject,content) VALUES('文章标题:Empty_clob()的使用方法',EMPTY_CLOB())";
Connection conn = db.getConnection();
conn.setAutoCommit(false);

PreparedStatement ptmt = conn.prepareStatement(sqlBuffer.toString());
ptmt.executeUpdate();
strSql = "select content from article where subject = "+subject+" for update ";
ResultSet rs = ptmt.executeQuery(strSql);
if (rs.next()) {
        /**//* 取出此CLOB对象 */
        oracle.sql.CLOB clob = null;
        clob = (oracle.sql.CLOB) rs.getClob("content");
        /**//* 向CLOB对象中写入数据 */
        BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());
        out.write(content);
        out.close();
        out = null;
        conn.commit();
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics