简体   繁体   English

使用 oracle jdbc 模板在 java 中创建新的数据库连接

[英]Creation of new database connection in java using oracle jdbc template

/* connection pool created with 5 connections based on the region specific.
 with below code it will get connection from connection pool which is already created.*/

Connection con = DatasourceClient.getDataSourceMap.get(region).getConnection();
OracleConnection oConn = con.unwrap(oracle.jdbc.OracleConnection.class);

Will above code will get two connections from pool and do i need to close both con and Oconn?上面的代码会从池中获得两个连接,我是否需要同时关闭 con 和 Oconn?

i am getting pool exhausted and connection closed exceptions tried many ways by changing pool properties.我通过更改池属性尝试了很多方法来耗尽池并且连接关闭异常。 So just want to know what above code is doing.所以只想知道上面的代码在做什么。

tried closing the above connections but didn't get any difference results.尝试关闭上述连接,但没有得到任何不同的结果。

Using Oracle Jdbc template instead of spring jdbc because in my procedures there are array values which in few cases only input, in some cases only output and other both INOUT. Using Oracle Jdbc template instead of spring jdbc because in my procedures there are array values which in few cases only input, in some cases only output and other both INOUT.

Can any one help me in this please?有人可以帮我吗? Thank you.谢谢你。

No, it will get only a single connection out, which you then unwrap to it's actual class.不,它只会输出一个连接,然后您将其解包为实际的 class。

However you will need to call con.close() (and never oCon.close() ) to return the connection back to the pool.但是,您需要调用con.close() (而不是oCon.close() )将连接返回到池中。 This is because the wrapper's close() doesn't actually close the connection, it returns it back to the pool.这是因为包装器的close()实际上并没有关闭连接,而是将其返回到池中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM