提交批处理

时间:2017-04-25 19:14:53

标签: java oracle jdbc

我有一个基本上打开数据库连接的函数,将自动提交更改为false,运行批量更新,将自动提交重置为原始值,然后关闭数据库连接。

当我运行con.close()时,我得到了这个......

java.lang.NoClassDefFoundError: oracle/jdbc/OracleConnection$CommitOption
        at oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:2383) ~[ojdbc7-12.1.0.jar:12.1.0.2.0]
        at oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:2407) ~[ojdbc7-12.1.0.jar:12.1.0.2.0]
        at org.apache.tomcat.dbcp.dbcp2.DelegatingConnection.commit(DelegatingConnection.java:373) ~[tomcat-dbcp.jar:8.5.11]
        at org.apache.tomcat.dbcp.dbcp2.DelegatingConnection.commit(DelegatingConnection.java:373) ~[tomcat-dbcp.jar:8.5.11]

ojdbc7-12.1.0.jar在我的WEB-INF / lib

这是我的示例代码(针对更多上下文进行了编辑)

Connection con = DBConnection.openDBConnection(env);
if (null == con) {
    return false;
}
PreparedStatement ps = null;

try {
    ps = con.prepareStatement(query);

    for (ProcItem proc : listitems)  {
        ps.setString(1, junk);
        ps.addBatch();
    }
} catch (SQLException e) {
    logger.error("Failed to create process insert batch");
    e.printStackTrace();
    success = false;
}

logger.trace("Finished creating batch update");

try {
    boolean ac = con.getAutoCommit();
    con.setAutoCommit(false);
    ps.executeBatch();
    con.commit();                     // this is the line throwing the exception
    con.setAutoCommit(ac);
    logger.trace("Finished running batch update");
} catch (SQLException e) {
    logger.error("Failed to execute process insert batch");
    e.printStackTrace();
    success = false;
} finally {
    try { if (null != ps) { ps.close(); } } catch (SQLException e) {}
    con.close();
}

0 个答案:

没有答案