如果是插入数据,先插入一个empty_blob(),更新数据就update为empty_blob()
然后select 一次,获得该 blob
比如获得的blob 为
Blob blob = resultset.getBlob(“xxx”);
然后调用
OutputStream os = blob.setOutputStream(1);
os.write(your_byte);
—详细代码如下—
try{
conn = this.getConnection();
conn.setAutoCommit(false);
java.sql.Statement st = conn.createStatement();
String sql1 = “insert into test_image(test_id,image) values (“123”,empty_blob)”;
System.out.println(“———>”+sql1);
String stl2 = “select image from test_image where test_id=’”+test.getId()+”’ for update”;
ResultSet rs = st.executeQuery(stl2);
OutputStream outStream = null;
if (rs.next())
{
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(“image”);
outStream = blob.getBinaryOutputStream();
outStream.write(byte[],0, byte[].length);
}
outStream.flush();
outStream.close();
conn.commit();
conn.close();
}