0

I am trying to create a UniversalConnectonPool using the code below:

// Read and process properties
PoolDataSource poolDataSource = createUniversalConnectionPool();
    
universalConnectionPoolManager = UniversalConnectionPoolManagerImpl.getUniversalConnectionPoolManager();
    
universalConnectionPoolManager.createConnectionPool((UniversalConnectionPoolAdapter) poolDataSource);
    
universalConnectionPoolManager.startConnectionPool(getSchema());

.
.
.
.

UniversalConnectionPool universalConnectionPool = universalConnectionPoolManager.getConnectionPool(getSchema());
UniversalPooledConnection universalPooledConnection = universalConnectionPool.borrowConnection(universalConnectionPool.getConnectionRetrievalInfo());

connection = (Connection) universalPooledConnection.getPhysicalConnection();

But the third line universalConnectionPoolManager.createConnectionPool((UniversalConnectionPoolAdapter) poolDataSource); throws the exception:

Caused by: oracle.ucp.UniversalConnectionPoolException: Universal Connection Pool already exists in the Universal Connection Pool Manager. Universal Connection Pool cannot be added to the Universal Connection Pool Manager
        at oracle.ucp.util.UCPErrorHandler.newUniversalConnectionPoolException(UCPErrorHandler.java:421)
        at oracle.ucp.util.UCPErrorHandler.newUniversalConnectionPoolException(UCPErrorHandler.java:389)
        at oracle.ucp.util.UCPErrorHandler.newUniversalConnectionPoolException(UCPErrorHandler.java:403)
        at oracle.ucp.admin.UniversalConnectionPoolManagerBase.setConnectionPool(UniversalConnectionPoolManagerBase.java:599)
        at oracle.ucp.admin.UniversalConnectionPoolManagerBase.createConnectionPool(UniversalConnectionPoolManagerBase.java:559)
        ... 30 more

Can you please tell me what I am doing wrong here? I am new to using Connection Pools, so still learning the ins-and-outs of it.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
hell_storm2004
  • 1,401
  • 2
  • 33
  • 66

1 Answers1

0

You cannot have more than one pools with same name. In your case it seems you already have an existing pool with same name. You can refer UCP code sample here.

Also, to borrow and return connection to pool you can use below standard APIs. Please note that calling poolDataSource.getConnection() internally creates and starts the pool if it was not already started.

// borrows a connection
Connection conn = poolDataSource.getConnection();
// return connection to pool
conn.close();
  • The sample code in the link is already written in `createUniversalConnectionPool()`. And since this is at server startup, I doubt that there is any other data source created. – hell_storm2004 Jun 17 '21 at 08:12
  • // Read and process properties PoolDataSource poolDataSource = createUniversalConnectionPool();This line is enough to configure the pool. After this you can simply call poolDataSource.getConnection() to borrow a connection from pool. Calling getConnection() will internally create and start the pool, no need to do it explicitly. – Saurabh Verma Jun 18 '21 at 10:12