java.sql.SQLException: ORA-01000: maximum open cursors exceeded

OracleJava大约 985 字

错误信息

java.sql.SQLException: ORA-01000: maximum open cursors exceeded

原因

已经达到一个进程打开的最大游标数

long currentId = 1;
long maxId = 100;
long step = 2;
Connection conn = null;
try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    String url = "jdbc:oracle:thin:@//127.0.0.1:1521/orcl";
    conn = DriverManager.getConnection(url, "username", "password");
    String sql = "DELETE FROM SEND_INFO WHERE ID < ?";

    while (currentId <= maxDelId) {
        conn.setAutoCommit(false);
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        preparedStatement.setLong(1, currentId);
        preparedStatement.execute();
        conn.commit();
        currentId += step;
    }
} catch (Exception e) {
    e.printStackTrace();
}

修改

PreparedStatement执行后关闭

preparedStatement.close();

PreparedStatement preparedStatement = conn.prepareStatement(sql);
preparedStatement.setLong(1, currentId);
preparedStatement.execute();
preparedStatement.close();
conn.commit();
阅读 349 · 发布于 2019-07-08

————        END        ————

扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看换一批