大家好,IBATIS操作CLOB字段的问题,原来是这么操作的:
TABLE:
ID  VARCHAR2(2)
CONTENNT CLOB在程序中插入时:
String id = "12";
String content="helloworld";IBATIS执行插入语句 INSERT INTO TABLE VALUES(#id#,#content#)
是可以执行成功但是当content内容非常大,有10M左右会比较慢,请问有什么解决的方法吗?ibatisCLOB

解决方案 »

  1.   

    但用JDBC方式插入,非常快。ResultSet rset = stmt.executeQuery("select * from basic_lob_table");
    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); System.out.println("---------"
    + sf.format(Calendar.getInstance().getTime()));
    while (rset.next()) {
    // Get the lobs
    BLOB blob = ((OracleResultSet) rset).getBLOB(2);
    CLOB clob = ((OracleResultSet) rset).getCLOB(3);
    // Change the lob contents
    fillClob(clob, 8000000); 
    }
    System.out.println("---------"
    + sf.format(Calendar.getInstance().getTime()));
    rset.close();
    stmt.close();
    conn.close();
    其中:
    static void fillClob(CLOB clob, long length) throws Exception {
    Writer outstream = clob.getCharacterOutputStream(); int i = 0;
    int chunk = 10; while (i < length) {
    outstream.write(i + "hello world", 0, chunk); i += chunk;
    if (length - i < chunk)
    chunk = (int) length - i;
    }
    outstream.close();
    }打印结果:
    // ---------20121225 18:17:58
    // ---------20121225 18:18:03
      

  2.   

    clob是通过流的形式将文件写入数据库的,如果文件类容很大,肯定会影响性能。
    如果硬是内容较大,需要用到clob,建议直接将文件上传