Java Connection Pooling

混江龙づ霸主 提交于 2019-12-01 06:35:15
Paul Bellora

Note: I assume we're talking about the java.sql.Connection interface.

Can a pool of connections only be used on a certain computer? Like ComputerA cannot share its connection pool with ComputerB?

A connection exists between a running application and a database. Naturally, two different machines can't share the same running application, so they can't share connections with a database.

Where should connection.close() be placed?

You should always make sure to call close() on a Connection instance after using it (typically in a finally block). If pooling is being used, this will actually return the connection to the pool behind the scenes. Reference: Closing JDBC Connections in Pool

Is it correct to use a connection ONLY when selecting/loading record? After I got the returned records/data I close the connection at finally statement.

Yes, that's correct. You don't want to manually hang on to a Connection reference - use it to execute SQL/DML and then check it back into the pool by calling close() in the finally block, just like you're doing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!