风中小郎君

导航

EMPTY_CLOB()/EMPTY_BLOB()使用

在向带有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()) {
        

posted on 2016-01-12 16:13  风中小郎君  阅读(595)  评论(0)    收藏  举报