Solve ora-01000 maximum open cursors exceeded java.sql.SQLException


In this post post we will solve Solve ora-01000 maximum open cursors exceeded java.sql.SQLException



What causes the Solve ora-01000 maximum open cursors exceeded java.sql.SQLException problem in JDBC java-
  • Not closing the JDBC Statement object can cause maximum open cursors exceeded java.sql.SQLException,
  • Not closing the JDBC PreparedStatement object can cause maximum open cursors exceeded java.sql.SQLException,
  • Not closing the JDBC CallableStatement object can cause maximum open cursors exceeded java.sql.SQLException,
  • Not closing the JDBC ResultSet object and
  • Not closing the JDBC Connections object can cause maximum open cursors exceeded java.sql.SQLException


Solution to ora-01000 maximum open cursors exceeded java.sql.SQLException problem in JDBC java-

You must ensure that you close all the JDBC Statement, PreparedStatement, CallableStatement , ResultSet and Connections in java to avoid ora-01000 maximum open cursors exceeded java.sql.SQLException in java. You must always close all the above mentioned objects in finally block in java because finally block is always executed irrespective of exception is thrown or not by java code.
Example of closing PreparedStatement, ResultSet and Connections in finally block in java-

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/** Copyright (c), AnkitMittal JavaMadeSoEasy.com */
public class JdbcBestPracticeExampleInJava {
   public static void main(String... arg) {
          Connection con = null;
          PreparedStatement prepStmt = null;
          ResultSet rs = null;                 
          try {
                 // Logic ..
          } catch (ClassNotFoundException e) {
                 e.printStackTrace();
          } catch (SQLException e) {
                 e.printStackTrace();
          }
          finally{
                 try {
                       if(rs!=null) rs.close(); //close resultSet
                       if(prepStmt!=null) prepStmt.close(); //close PreparedStatement
                       if(con!=null) con.close(); // close connection
                 } catch (SQLException e) {
                       e.printStackTrace();
                 }
          }
   }
}



No comments:

Post a Comment