谈笑有鸿儒,往来无白丁

在恰当的时间、地点以恰当的方式表达给恰当的人...  阅读的时候请注意分类,佛曰我日里面是谈笑文章,其他是各个分类的文章,积极的热情投入到写博的队伍中来,支持blogjava做大做强!向dudu站长致敬>> >

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篇章

feedback:
# re: while inserting a large blob using jdbc, the application fails with:ora-22990
2015-08-25 14:03 | 坏男孩
the following error occurs while inserting empty blob to return blob locators.

ora-22990: lob locator cannot span transaction

dml statements were executed within a for loop to insert an empty blob and an attempt to fetch is made followed by commit within the loop.
solution

it is not advisable to use a commit inside a loop. use commit after the loop ends.
  回复  
  
网站地图