Posted on 2009-11-02 15:01
瘋狂 閱讀(359)
評論(0) 編輯 收藏 所屬分類:
java 、
database
mysql 的機制其實應該是這樣的:當你數據庫緩存中的數據量達到tmp_table_size時,它會自動提交一次,然后繼續接下來的操作,每tmp_table_size刷新數據庫緩存
MySQL 中的 BLOB 數據由四種類型體現,分別是 TINYBLOB 其容量為 256 字節、BLOB 其容量為 64KB、MEDIUMBLOB 其容量為 16MB、LONGBLOB 其容量為 4GB。
CLOB類型默認為1m 如果大于的話可能會出現
Packet for query is too large (37748784 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable
異常 這是可以在
[mysqld]下面添加 max_allowed_packet=10M來擴大限制
在 jdk 6。0 以前 向數據庫插入clob 和blob數據的操作方法:
void setBinaryStream(int parameterIndex, java.io.InputStream x, int length)方法
而在jdk 6.0以后就可以用
void setClob(int parameterIndex, Reader reader)
void setBlob(int parameterIndex, InputStream inputStream)方法來插入clob/blob
讀取時候可以用讀取流來處理或者用:
clob的時候可以
用 Clob.getSubString(pos, length)不過length是個int型的
或者用
- Clob c = rs.getClob("clumn");
- StringBuffer a = new StringBuffer(1024);
- Reader r = c.getCharacterStream();
- char[] cc = new char[1];
- int i = -1;
- while((i =r.read(cc))!=-1){
- a.append(cc);
- }
Clob c = rs.getClob("clumn");
StringBuffer a = new StringBuffer(1024);
Reader r = c.getCharacterStream();
char[] cc = new char[1];
int i = -1;
while((i =r.read(cc))!=-1){
a.append(cc);
}
讀取blob可以用:
Blob b = rs.getBlob("clumn");
java.io.InputStream getBinaryStream ()或者getBytes(pos, length)