通用连接池已存在错误(Oracle UCP)



我正试图使用以下代码创建一个UniversalConnectonPool:

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

但是第三行universalConnectionPoolManager.createConnectionPool((UniversalConnectionPoolAdapter) poolDataSource);抛出异常:

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

你能告诉我我在这里做错了什么吗?我是使用连接池的新手,所以仍在学习它的来龙去脉。

不能有多个具有相同名称的池。在您的情况下,您似乎已经有了一个同名的现有池。您可以在此处参考UCP代码示例。

此外,要借用并返回到池的连接,您可以使用以下标准API。请注意,调用poolDataSource.getConnection((会在内部创建并启动尚未启动的池。

// borrows a connection
Connection conn = poolDataSource.getConnection();
// return connection to pool
conn.close();

相关内容

  • 没有找到相关文章

最新更新