JDBC Connection pooling using C3P0

后端 未结 4 1461
生来不讨喜
生来不讨喜 2020-12-23 21:04

Following is my helper class to get DB connection:

I\'ve used the C3P0 connection pooling as described here.

public class DBConnection {

    private         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-23 21:41

    DAOs should not be responsible for acquiring a connection to the database. They have no way to know when they're being used as part of a larger transaction. You should be passing the data source or connection instance into the DAO.

    If any of the calls to close in your finally block throw an exception, none of the ones that follow will be called. Each one needs to be in its own try/catch block. I put them into a utility class as static methods.

提交回复
热议问题