Universal Connection Pool already exists error (Oracle UCP)

5.6k Views Asked by At

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.

1

There are 1 best solutions below

2
Saurabh Verma On

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();