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();
    }
  • 相关阅读:
    nodepad++中的正则表达式匹配和替换操作。
    QT Creator配置环境和安装
    圣诞树小程序的制作
    C#编辑xml文件
    delegate里的Invoke和BeginInvoke
    记录RFID操作错误
    关于Panel隐藏横向滚动条
    随笔
    Java图形打印 上下对称三角星
    Centos 7.5安装 Redis 5.0.0
  • 原文地址:https://www.cnblogs.com/ungshow/p/1312675.html
Copyright © 2011-2022 走看看