你的getPooledConnection()应该是单独的方法,构造函数里面应该做初始化连接池对象用,
释放开pool
你只要断开连接就可以了!
容器会自动回收CONNECTION对象的

解决方案 »

  1.   

    调用getPooledConnection()在构造函数里面?还是放到单独的方法里?
      

  2.   

    这种得数据库得连接应该专门做个类。
    在finally里把result,statement,和connectionclose掉就行了。
      

  3.   

    import java.sql.*;
    import javax.sql.*;
    import oracle.jdbc.driver.*;
    import oracle.jdbc.pool.*;class CCache1
    {
      public static void main (String args [])
           throws SQLException
      {
        OracleConnectionCacheImpl ods = new OracleConnectionCacheImpl();
        ods.setURL("jdbc:oracle:oci8:@");
        ods.setUser("scott");
        ods.setPassword("tiger");     // Set the Max Limit
        ods.setMaxLimit (3);    Connection conn1 = null;
        conn1 = ods.getConnection();
        if (conn1 != null)
          System.out.println("Connection 1 " + " Succeeded!");
        else
          System.out.println("Connection 1 " + " Failed !!!");    Connection conn2 = null;
        conn2 = ods.getConnection();
        if (conn2 != null)
          System.out.println("Connection 2 " + " Succeeded!");
        else
          System.out.println("Connection 2 " + " Failed !!!");    Connection conn3 = null;
        conn3 = ods.getConnection();
        if (conn3 != null)
          System.out.println("Connection 3 " + " Succeeded!");
        else
          System.out.println("Connection 3 " + " Failed !!!");    Connection conn4 = null;
        conn4 = ods.getConnection();
        if (conn4 != null)
          System.out.println("Connection 4 " + " Succeeded!");
        else
          System.out.println("Connection 4 " + " Failed !!!");    Connection conn5 = null;
        conn5 = ods.getConnection();
        if (conn5 != null)
          System.out.println("Connection 5 " + " Succeeded!");
        else
          System.out.println("Connection 5 " + " Failed !!!");
        System.out.println("Active size : " + ods.getActiveSize());
        System.out.println("Cache Size is " + ods.getCacheSize());    // Close 3 logical Connections
        conn1.close();
        conn2.close();
        conn3.close();    System.out.println("Active size : " + ods.getActiveSize());
        System.out.println("Cache Size is " + ods.getCacheSize());    // close the Data Source
        ods.close();    System.out.println("Active size : " + ods.getActiveSize());
        System.out.println("Cache Size is " + ods.getCacheSize());
      }
    }例子自己看看