IBATIS操作CLOB字段的问题
大家好,IBATIS操作CLOB字段的问题,原来是这么操作的:TABLE:
ID VARCHAR2(2)
CONTENNT CLOB
在程序中插入时:
String id = "12";
String content="helloworld";
IBATIS执行插入语句 INSERT INTO TABLE VALUES(#id#,#content#)
是可以执行成功但是当content内容非常大,有10M左右会比较慢,请问有什么解决的方法吗? ibatis CLOB --------------------编程问答-------------------- 自己UP一下。 --------------------编程问答-------------------- 内容打的话本来就会慢 --------------------编程问答-------------------- 但用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 --------------------编程问答-------------------- clob是通过流的形式将文件写入数据库的,如果文件类容很大,肯定会影响性能。
如果硬是内容较大,需要用到clob,建议直接将文件上传。。。 --------------------编程问答-------------------- 数据库不建议存储大文件........。毕竟写文件数据到数据库和直接和磁盘进行IO操作,效率上显而易见了 --------------------编程问答-------------------- +1.数据太大就别放数据库了。
补充:Java , Java EE