Java Oracle开放式游标ora-1000错误;超过最大打开游标数。”;

Java Oracle开放式游标ora-1000错误;超过最大打开游标数。”;,java,database,oracle,cursor,Java,Database,Oracle,Cursor,我已经完成了与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 ('"

我已经完成了与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张唱片。 我发现一些主题说应该更改配置,但我不能更改配置


是否有其他方法解决此错误?

finally
块中关闭语句

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

finally
块中关闭语句

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

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

在使用语句后关闭该语句是一种很好的做法

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

将解决您的问题。

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

在使用语句后关闭该语句是一种很好的做法

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

将解决您的问题。

请注意佩特卡的评论:

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


使用在值中绑定的PreparedStatements,您将只创建一个唯一的SQL insert语句,该语句只需解析一次,不会使共享池混乱。您的数据库管理员将为此向您表示感谢。

请注意佩特卡的评论:

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


使用在值中绑定的PreparedStatements,您将只创建一个唯一的SQL insert语句,该语句只需解析一次,不会使共享池混乱。您的数据库管理员将为此感谢您。

write statement.close()……执行后……它会出现,因为您没有关闭它。请。这不是PHP,用这种方式创建查询即使在那里也是不受欢迎的。。。使用准备好的报表。相信我,你以后会感谢这个决定的……写一个语句。close()……在执行之后……它来了,因为你没有关闭它。这不是PHP,用这种方式创建查询即使在那里也是不受欢迎的。。。使用准备好的报表。相信我,你以后会感谢这个决定的……谢谢你,它现在起作用了!谢谢,现在可以工作了!好的,谢谢,我会搜索并尝试它。顺致敬意,好的,谢谢,我会搜索并尝试它。顺致敬意,