gpt4 book ai didi

java - OrdImage LoadFromFile 异常

转载 作者:行者123 更新时间:2023-11-30 05:22:26 26 4
gpt4 key购买 nike

我正在尝试将图像加载到 Oracle 多媒体数据库中。我的 OrdImage.loadDataFromFile() 方法有问题,它会抛出 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

我使用的代码:

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();

...
}

行抛出异常:

imgProxy.loadDataFromFile("/home/anton/Documents/1.MIT_zima/UPA/upa-project/app/Kataster/car42.gif");

最佳答案

试试这个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;

关于java - OrdImage LoadFromFile 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59335561/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com