I am using c3p0 – ComboPooledDataSource. I am initializing once as below.
private void init() {
cpds = new ComboPooledDataSource();
cpds.setDriverClass(driverName);
cpds.setJdbcUrl(url);
cpds.setUser(userName);
cpds.setPassword(pwd);
}
I am getting a connection from the pool as below
public synchronized Connection getLocalConnection(String ipAddr)
throws SQLException {
return cpds.getConnection();
}
But i am not sure whether its the right way to return the connection back to the pool when i finish executing a query. I guess the
conn.close()
just returns the connection back to the pool instead of REALLY CLOSING the connection.
Am i correct or is there any other way around? Pls help.
This is initializing code
And you get connection from DataSource.
And to close the connection just call close() method.