您是否需要关闭从jdbc连接池获得的连接? [英] Do you need to close the connection you get from jdbc connection pool?

查看:422
本文介绍了您是否需要关闭从jdbc连接池获得的连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下代码

DataSource source = (DataSource) (new InitialContext()).lookup("jdbc/myName"); 
Connection connnection = source.getConnection() 

//use the connection to do some database operations...

最后,我还是应该叫


connection.close()释放

at the end, should I still call

connection.close() to release the resource?

如果连接来自连接池,如果我什么都不做,则连接应该自动返回到池中,对吧?

If the connection is from a connection pool, if I don't do anything, the connection should be automatically returned to the pool, right?

另一方面,如果我将其关闭,则对连接池是否会有不利影响(即,经过几次呼叫后,将不会有任何连接)留在池中?)

On the other hand, if I close it, is there gonna be any adverse effect on the connection pool (ie, after several calls, there won't be any connection left in the pool?)

推荐答案

答案是肯定的,然后检查在池中关闭JDBC连接 JDBC连接池最佳做法以获取更多信息。

The answer is yes, and check Closing JDBC Connections in Pool and JDBC Connection Pooling Best Practices for more information.

这篇关于您是否需要关闭从jdbc连接池获得的连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆