【问题标题】:Oracle Open cursors ora-1000 errors, "Maximum open cursors exceeded." [duplicate]Oracle Open cursors ora-1000 错误,“Maximum open cursors exceeded”。 [复制]
【发布时间】:2013-10-11 06:42:18
【问题描述】:

我已经连接到 Oracle 数据库。 现在我面对

ORA-01000: maximum open cursors exceeded

我用代码插入数据:

public static void OracleJDBC(String Serial_Number, String Charged_MDN) {

     String dataInsertQuery = "insert into CDR_Huawei (Serial_Number, Charged_MDN) values ('" + Serial_Number + "', '" + Charged_MDN + "')";
     String dataSelectQuery = "select * from CDR_Huawei";
     Statement statement = null;

    try {
    statement = connection.createStatement();
    statement.execute(dataInsertQuery);
    //System.out.println("Data Inserted Successfully");

    } catch (SQLException e) {
            e.printStackTrace();
    }
   }

它仅适用于前 500 条记录,然后出现错误 Ora-1000。 我总共有大约 6000 条记录。 我发现一些主题说应该更改配置,但我无法更改配置。

还有其他方法可以解决这个错误吗?

【问题讨论】:

  • write statement.close() ....执行后...它来了,因为你没有关闭它
  • 请。这不是 PHP,即使在那里创建查询也是不受欢迎的……使用 PreparedStatements。你稍后会感谢这个决定的,相信我......

标签: java database oracle cursor


【解决方案1】:

finally 块中结束您的声明。

try {
    statement = connection.createStatement();
    statement.execute(dataInsertQuery);
} catch (SQLException e) {
        e.printStackTrace();
} finally {
    if (statement != null) statement.close();
}

【讨论】:

  • 谢谢你,它现在可以工作了!
【解决方案2】:

每次编写时都会生成新的语句对象 statement = connection.createStatement()

使用后关闭语句是个好习惯...

 statement.close(); after `statement.execute(dataInsertQuery);`

会解决你的问题。

【讨论】:

    【解决方案3】:

    提请注意 ppeterka 评论的额外答案:

    你真的应该在这里使用 PreparedStatements。原因是您当前正在向数据库发送 6000 个唯一的 SQL 插入语句。这些语句是唯一的,因为插入语句的值粘在您的语句文本中。数据库必须解析每个唯一语句并将其放入共享池中以供重用。但它不会重复使用,因为它们是独一无二的。

    使用在值中绑定的 PreparedStatements,您将只创建一个唯一的 SQL 插入语句,该语句只需要解析一次,并且不会弄乱共享池。你的数据库管理员会感谢你的。

    【讨论】:

    • 好的,谢谢,我会搜索并尝试一下。最好的问候!
    猜你喜欢
    • 2018-10-23
    • 2015-09-30
    • 2013-01-04
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    • 2013-12-07
    • 1970-01-01
    • 2021-09-10
    相关资源
    最近更新 更多