users@glassfish.java.net

Re: Problem closing Glassfish JDBC connection (from pool)

From: Shalini Muthukrishnan <Shalini.Muthukrishnan_at_Sun.COM>
Date: Thu, 17 Jan 2008 18:05:19 +0530

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
>
>
>