Commons Dbcp
  1. Commons Dbcp
  2. DBCP-265

Connection close handling DatabaseMetaData exceed max open cursor oracle

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.1, 1.2.2
    • Fix Version/s: 1.3
    • Labels:
      None
    • Environment:

      Windows/Unix, Oracle 10gR2, JDK 1.4, Oracle JDBC Driver 10.2.0.1.

      Description

      Hello,

      i was suprised by following behavior:
      /**

      • Here all is OK, the finally block closes the connection and implicit the statement and the resultset. If called repeatedly, only one cursor is used.
      • @throws SQLException
        */
        public void test2() throws SQLException{
        Connection con = null;
        try{
        con = dataSource.getConnection();
        Statement statement = con.createStatement();
        ResultSet resultSet = statement.executeQuery("select * from MyTable");
        if(resultSet.next())
        resultSet.getString(1);
        }finally {
        if (con != null) {
        con.close();
        }
        }
        }

      But doing this repeatedly
      /**

      • Danger: exceeds max open cursors if called repeatedly.
      • @throws SQLException
        */
        public void test1() throws SQLException{
        Connection con = null;
        try{
        con = dataSource.getConnection();
        DatabaseMetaData metaData = con.getMetaData();
        ResultSet schemas = metaData.getSchemas();
        }finally {
        if (con != null) {
        con.close();
        }
        }
        }
        exceeds max open cursors on the database.

      DataSource created with following block:
      dataSource = new BasicDataSource();
      dataSource.setDriverClassName("oracle.jdbc.OracleDriver");
      dataSource.setUsername("myuser");
      dataSource.setPassword("mypasswd");
      dataSource.setUrl("jdbc:oracle:thin:@192.168.0.1:1521:mydb");

      Of course, explicit closing the 'schemas' ResultSet in the second case solves the problem.

      I am not certainly sure my expected behavior is conform to the jdbc spec. But without using the BasicDatasource this problem doesnt occure.

      I inspected the code and saw, that org.apache.commons.dbcp.BasicDataSource (or more specific, DelegatingConnection) doesnt track Connections and ResultSets created from DatabaseMetadata-Object.Only created Statements form DelegatingConnection are tracked. And in PoolableConnectionFactory.passivateObject() only these statements are closed and warnings are cleared on the underlying connection.

        Activity

        pd created issue -
        Hide
        Henri Yandell added a comment -

        Sounds like we need a DelegatingMetaData.

        Show
        Henri Yandell added a comment - Sounds like we need a DelegatingMetaData.
        Henri Yandell made changes -
        Field Original Value New Value
        Fix Version/s 1.3 [ 12311977 ]
        Hide
        Mark Thomas added a comment -

        This has been fixed in svn and will be included in 1.3 onwards

        Show
        Mark Thomas added a comment - This has been fixed in svn and will be included in 1.3 onwards
        Mark Thomas made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Phil Steitz made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            pd
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development