Search code examples
javadatabaseoraclecursor

Oracle Open cursors ora-1000 errors, "Maximum open cursors exceeded."


I've done connection to Oracle Database. Now I'm facing

ORA-01000: maximum open cursors exceeded

I used code to insert data:

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

It works only for first 500 records, then I have the error Ora-1000. I have about 6000 records in total. I found some topics saying that configuration should be changed, but I can't change configuration.

Is there another way to solve this error?


Solution

  • Close your statement in a finally block.

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