Oracle 下操作blob字段是否会产生大量redo
操作blob字段是否会产生大量redo,答案是不会,下面来做一个实验,测试Oracle数据库版本是11.2.0.1.0:
操作blob字段是否会产生大量redo,答案是不会,下面来做一个实验,测试Oracle数据库版本是11.2.0.1.0:
在CentOS 6.4下安装Oracle 11gR2(x64)
Oracle 11gR2 在VMWare虚拟机中安装步骤
Debian 下 安装 Oracle 11g XE R2
--创建一张表做测试之用
create table test_blob
(
id number,
tupian blob
);
import java.io.FileInputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.sql.BLOB;
public class BlobExample {
static final String driver_class = "oracle.jdbc.driver.OracleDriver";
static final String connectionURL = "jdbc:oracle:thin:@10.10.15.25:1521:orcl";
static final String userID = "test";
static final String userPassword = "test";
private void insertTestBlob() {
Connection conn=null;
Statement stm=null;
ResultSet rs=null;
BLOB blob = null;
FileInputStream fin=null;
OutputStream out=null;
try{
conn = DriverManager.getConnection(connectionURL, userID, userPassword);
stm = conn.createStatement();
conn.setAutoCommit(false);
String sql = "insert into test_blob values(1,EMPTY_BLOB())";
stm.executeUpdate(sql);
rs = stm.executeQuery("SELECT tupian FROM test_blob WHERE id=1 FOR UPDATE ");
fin = new FileInputStream("d://20130317.jpg");
byte[] blobBuf = new byte[(int)fin.available()];
fin.read(blobBuf);
fin.close();
if(rs.next()) {
blob = (oracle.sql.BLOB)rs.getBlob(1);
out = blob.getBinaryOutputStream();
out.write(blobBuf);
out.close();
conn.commit();
}
}catch(Exception e){
e.printStackTrace();
}finally{
try {
rs.close();
stm.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static void main(String args[]){
BlobExample blobClobExample = new BlobExample();
blobClobExample.insertTestBlob();
}
}
更多详情见请继续阅读下一页的精彩内容:
,上一篇: 安博亚威每2天诞生1名CCIE的秘密
下一篇: 向多个表填入相同字段的记要求指导