zoukankan      html  css  js  c++  java
  • 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()) {
            
    /* 取出此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();
    }
  • 相关阅读:
    宿舍助手app——个人工作第四天
    宿舍助手app——个人工作第三天
    对QQ输入法的评价
    冲刺9
    冲刺8
    冲刺7
    冲刺6
    冲刺5
    冲刺4
    冲刺3
  • 原文地址:https://www.cnblogs.com/ungshow/p/1312675.html
Copyright © 2011-2022 走看看