java.sql.SQLException: - ORA-01000: maximum open cursors exceeded

后端 未结 13 1624
鱼传尺愫
鱼传尺愫 2020-11-22 08:36

I am getting an ORA-01000 SQL exception. So I have some queries related to it.

  1. Are maximum open cursors exactly related to number of JDBC connections, or are t
13条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 08:56

    Correct your Code like this:

    try
    { //method try starts  
      String sql = "INSERT into TblName (col1, col2) VALUES(?, ?)";
      pStmt = obj.getConnection().prepareStatement(sql);
      pStmt.setLong(1, subscriberID);
      for (String language : additionalLangs) {
        pStmt.setInt(2, Integer.parseInt(language));
        pStmt.execute();
      }
    } //method/try ends
    finally
    { //finally starts
       pStmt.close()
    } 
    

    Are you sure, that you're really closing your pStatements, connections and results?

    To analyze open objects you can implment a delegator pattern, which wraps code around your statemant, connection and result objects. So you'll see, if an object will successfully closed.

    An Example for: pStmt = obj.getConnection().prepareStatement(sql);

        class obj{ 
    
        public Connection getConnection(){
        return new ConnectionDelegator(...here create your connection object and put it into ...);
    
        } 
    }
    
    
    class ConnectionDelegator implements Connection{
        Connection delegates;
    
        public ConnectionDelegator(Connection con){
           this.delegates = con;
        }
    
        public Statement prepareStatement(String sql){
            return delegates.prepareStatement(sql);
        }
    
        public void close(){
            try{
               delegates.close();
            }finally{
               log.debug(delegates.toString() + " was closed");
            }
        }
    }
    

提交回复
热议问题