cause
the oracle oracle.sql.blob outputstream writes the data in chunks. since autocommit defaults to true, the first chunk is committed. this results in the write operation for the next chunk of the blob to fail since it appears to be in the next transaction.
in those conditions, the ora-22990 exception will occur with any version of oracle jdbc driver.
solution
issue the setautocommit(false) command. then, explicitly commit the transaction after all of the blob chunks have been written to the row and the stream.close() method has been executed.
if using the oracle 10g jdbc driver (or greater version), a second solution consists of using the standard jdbc api (setbinarystream method of java.sql.preparedstatement interface). and in this case, autocommit can be set to true.
here is an example:
preparedstatement stmt = conn.preparestatement("insert into blobtest values (?,?)");
file fd = new file(testfile);
fis = new fileinputstream(fd);
stmt.setint(1,1);
stmt.setbinarystream(2,fis,(int)fd.length());
where blobtest is a table defined as the following:
sql> create table blobtest (id number (4), data blob);
posted on 2015-08-25 13:56
坏男孩 阅读(936)
评论(1) 编辑 收藏 所属分类:
oracle篇章