I am trying to load an image into Oracle multimedia database. I have problem with OrdImage.loadDataFromFile()
method which throws me a SQLException
java.sql.SQLException: ORA-22990: LOB locators cannot span transactions
ORA-06512: at "SYS.DBMS_LOB", line 1127
ORA-06512: at "ORDSYS.ORDSOURCE", line 801
ORA-06512: at "ORDSYS.ORDIMAGE", line 669
ORA-06512: at line 1
The code I use:
public void uploadImage(String filename) throws SQLException, IOException
{
...
// retrieve the previously created ORDImage object for future updating
Statement stmt2 = dbModel.getConnection().createStatement();
String selSQL = "select IMAGE from PHOTO where id="+test_id+" for update";
OracleResultSet rset = (OracleResultSet) stmt2.executeQuery(selSQL);
rset.next();
OrdImage imgProxy = (OrdImage)
rset.getORAData("IMAGE", OrdImage.getORADataFactory());
rset.close();
stmt2.close();
// load the media data from a file to the ORDImage Java object
try {
imgProxy.loadDataFromFile("/home/anton/Documents/1.MIT_zima/UPA/upa-project/app/Kataster/car42.gif");
}
catch (SQLException ex) {
System.err.println(ex);
}
// set the properties of the Oracle Mm object from the Java object
imgProxy.setProperties();
...
}
Exception is thrown by line:
imgProxy.loadDataFromFile("/home/anton/Documents/1.MIT_zima/UPA/upa-project/app/Kataster/car42.gif");
try this setAutoCommit(false)
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;