济南网站建设yeptask,成都网络营销公司排名收费标准,wordpress排除分类,知乎关键词搜索BLOB和CLOB都是大字段类型#xff0c; 1、BLOB是按二进制来存储的#xff0c;通常像图片、文件、音乐等信息就用BLOB字段来存储#xff0c;先将文件转为二进制再存储进去。 2、CLOB是可以直接存储文字的#xff0c;像文章或者是较长的文字#xff0c;就用CLOB存储#xf… BLOB和CLOB都是大字段类型 1、BLOB是按二进制来存储的通常像图片、文件、音乐等信息就用BLOB字段来存储先将文件转为二进制再存储进去。 2、CLOB是可以直接存储文字的像文章或者是较长的文字就用CLOB存储这样对以后的查询更新存储等操作都提供很大的方便。 Oracle中处理BLOB/CLOB字段的方式比较特别所以需要特别注意下面两点
在Oracle JDBC中采用流机制对 BLOB/CLOB 进行读写操作所以要注意不能在批处理中读写 BLOB/CLOB字段否则将出现 Stream type cannot be used in batching 异常。Oracle BLOB/CLOB 字段本身拥有一个游标cursorJDBC通过游标对Blob/Clob字段进行操作在Blob/Clob字段创建之前无法获取其游标句柄会出现 Connection reset by peer: socket write error 异常。
正确的做法是首先创建一个空 Blob/Clob 字段再从这个空 Blob/Clob字段获取游标例如下面的代码
PreparedStatement psconn.prepareStatement(insert into PICTURE(image,resume)
values(?,?));//通过oralce.sql.BLOB/CLOB.empty_lob()构造空Blob/Clob对象
ps.setBlob(1, oracle.sql.BLOB.empty_lob());
ps.setClob(2, oracle.sql.CLOB.empty_lob());ps.excuteUpdate();
ps.close();//再次对读出Blob/Clob句柄
psconn.prepareStatement(select image,resume from PICTURE where id? for update);
ps.setInt(1 , 100);ResultSet rsps.executeQuery();
rs.next();
oracle.sql.BLOB imgBlob(oracle.sql.BLOB)rs.getBlob(1);
oracle.sql.CLOB resClob(oracle.sql.CLOB)rs.getClob(2);//将二进制数据写入Blob
FileInputStream inStreamnew FileInputStream(c://image.jpg);
OutputStream outStreamimgBlob.getBinaryOutputStream();
byte[] bufnew byte[10240];
int len;
while(leninStream.read(buf)0){
outStream.write(buf, 0 ,len);
}
inStream.close();
outStream.cloese();//将字符串写入Clob
resClob.putString(1, this is a clob);//再将Blob/Clob字段更新到数据库
psconn.prepareStatement(update PICTURE set image? and resume? where id?);
ps.setBlob(1, imgBlob);
ps.setClob(2, resClob);
ps.setInt(3, 100 );ps.executeUpdate();
ps.close();