users@glassfish.java.net

Re: Problem closing Glassfish JDBC connection (from pool)

From: Dies Koper <dies_at_jp.fujitsu.com>
Date: Thu, 17 Jan 2008 21:52:24 +0900

Could it be that the maximum pool size of your JDBC connection pool
exceeds the maximum number of connections specified in your database?

The pool will not close the connections you acquired, it will keep them
open in its pool until its maximum is reached. That's way close() did
not seem to have any effect.

But the database also has a setting to specify the maximum number of
connections that can be simultaneously open.
You should not specify your pool size to be bigger than the number of
connections you allow your database to keep open.


Shalini Muthukrishnan wrote:
> Hi,
>
> I could not reproduce this issue in a standalone mode.
> In other words, i created a connection pool and a jdbc resource called
> "jdbc/someRes". I tried accessing this resource in a stand-alone program as
> c.lookup("jdbc/someRes");
> and i followed the similar steps you have mentioned here.
> I do not get this particular error.
>
> Are you also trying to do this in a stand-alone mode?
>
> Thanks,
> Shalini.
>
> HAcland wrote:
>> Hi,
>>
>> [code] DataSource db = DBCon.getDBCon();[/code]
>> ....
>> [code]
>> public class DBCon {
>>
>> public static DataSource getDBCon() {
>> try {
>> DataSource myDB = DBCon.getPWA();
>> return myDB;
>> } catch (NamingException ex) {
>> Logger.getLogger(DBCon.class.getName()).log(Level.SEVERE,
>> null,
>> ex);
>> return null;
>> }
>> }
>>
>> private static DataSource getPWA() throws NamingException {
>> Context c = new InitialContext();
>> return (DataSource) c.lookup("java:comp/env/PWA");
>> }
>> }[/code]
>>
>> The problem I am having is that even when I call [code]
>> db.getConnection().close();[/code]
>> it doesn't appear to close the connection because after a while i get an
>> error message from glassfish saying "Connection could not be allocated
>> because: Data source rejected establishment of connection, message from
>> server: "Too many connections"
>>
>> Is there a better way to close the connections Or am I just not doing it
>> correctly.
>>
>> Thanks
>>