0

So I am trying to understand how to build connection pools and to connect via java to an Oracle DB. i am trying to use dbcp2 to learn more about how all of this works. If I use the BasicDataSource I can connect and I see 5 connections via the number I set up when I created the pools like this.

private static BasicDataSource getDataSource() {

        {

            if (dataSource == null)
            {
                BasicDataSource ds = new BasicDataSource();
                ds.setUrl("jdbc:oracle:thin:@pdb_tac");
                ds.setUsername("hr");
                ds.setPassword("my_password");
                //ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
                ds.setDriverClassName("oracle.jdbc.replay.OracleDataSourceImpl");
                //ds.setDriverClass("oracle.jdbc.replay.OracleDataSourceImpl");
                ds.setDefaultAutoCommit(false);

                ds.setInitialSize(5);
                ds.setMinIdle(5);
                ds.setMaxIdle(10);
                ds.setMaxOpenPreparedStatements(100);

                dataSource = ds;
            }
            return dataSource;
        }

    }

Well, my issue is I need to be able to create a PoolingDataSource to deal with connecting to an Oracle RAC for high availability.

So I create my data source like this.

  private static DataSource setupDataSource(){

        String connectURI = "jdbc:oracle:thin:hr/my_password@pdb_tac";
        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI,null);

        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,null);
        ObjectPool objectPool = new GenericObjectPool(poolableConnectionFactory);

        poolableConnectionFactory.setPool(objectPool);

        PoolingDataSource dataSource = new PoolingDataSource(objectPool);





        return dataSource;

    }

Well when I connect I only see 1 connection to the database not 5 like I do when I use BasicDataSource. Can someone help me understand what I am doing wrong? Thanks.

cptkirkh
  • 107
  • 1
  • 9

0 Answers0