Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8445985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:48:20+00:00 2026-06-10T09:48:20+00:00

I made a java method to add a row to a database. I am

  • 0

I made a java method to add a row to a database. I am calling this method about 1000 plus times for testing purposes. I called the close() method on my prepared statement and i am still getting the oracle error whenever this method is called to insert a row.

Error

ORA-01000: maximum open cursors exceeded

Source Code

public void insertARow(ArrayList<String> row)
{
    try
    {
        //Proper SQL statement here, checked by running on DB  
        String insert = "INSERT INTO user.info(cola,colb) values(?,?)";

        //Add a row 
        PreparedStatement ps = con.prepareStatement(insert);//con is a connection object 
        //'row' is an arraylist of strings
        for(int i = 0; i < row.size(); i++ )
        {

            int j = 1 +  i ; 
            String temp = row.get(i);
            ps.setString(j , temp);
        }

        ps.executeUpdate();//The reason for problems !!!
        ps.close();

    }catch(SQLException e)
    {
        System.out.println("Cannot add row !");
        e.printStackTrace();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:48:22+00:00Added an answer on June 10, 2026 at 9:48 am

    If you’re trying to perform the same operation a 1000 times, I would advise re-using the same PreparedStatement or using addBatch() and executeBatch() combo.

    If you’re planning to re-use your PreparedStatement, here’s something that you can do:

    public void insertARow(PreparedStatement ps, ArrayList<String> row){
     //your code
    }
    
    public void calledMethod(){
     String insert = "INSERT INTO user.info(cola,colb) values(?,?)";
     PreparedStatement ps = null;
    
     try{
       ps = con.prepareStatement(insert);
       /**
        * Here you make the call to insertARow passing it the preparedstatement that you
        * have created. This in your case will be called multiple times.
        */
       insertARow(ps, row);
     }finally{
       if(ps != null){
         //close ps
       }
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner in Android development. My code crashes. I have made a simple Java method
I had a different problem first, so I made this post: Java JPanel mouse
I have made a java project and want to deliver it to a client
I have made a java swing GUI. Now I want to display a static
I have made a java application and have packed it into an executable jar
I have made a java application that stores data from a .csv file to
I have made a Java class where I have defined a constructor and some
I'm trying to use sbt to compile an Android Project made in Java, which
So I have a bit of a performance problem. I have made a java
I have a client jar made-up using java 1.6 and used enum and other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.