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.
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);
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 坏男孩
阅读(669) 评论(1) 编辑 收藏