You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Hans Sowa <ha...@gmail.com> on 2006/02/03 12:40:04 UTC

problem with JNDI

Hi

I'm working on a webapplikation using JNDI to lookup for a database
connection. Actually it works for several times and then it stopps and I
don't get an connection. I analysed it and found out that Method
getConnnection has a problem.

Here is my code:

protected Connection lookupJNDIConnection(final String resource) {
        InitialContext ic = null;
        try {
            System.out.println("will InitialContext");
            ic = new InitialContext();
            System.out.println("lookup nach comp/env");
            Context envContext = (Context) ic.lookup("java:/comp/env");
            System.out.println("lookup.");
            DataSource ds = (DataSource) envContext.lookup(resource);
            System.out.println("return getconnection.");
            return ds.getConnection();

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

I can see the out.println("return getconnection.") but the out.println after
that, in the method which calls the this method,  are not visible.

And for every sql statement I perform a lookup, get the connection, perform
the sql statement and then close the connection. Has anyone an idea what the
problem is?

Thanks in advance.

--
mfg Hans Sowa
mailto:hanssowa@gmail.com

Re: problem with JNDI

Posted by Hans Sowa <ha...@gmail.com>.
Hallo

I solved the problem. It is embarrasing to me but in some cases I didn't
close the connection. So therefore I had this problem.

Thanks.

2006/2/3, Hans Sowa <ha...@gmail.com>:
>
> Hi
>
> I'm working on a webapplikation using JNDI to lookup for a database
> connection. Actually it works for several times and then it stopps and I
> don't get an connection. I analysed it and found out that Method
> getConnnection has a problem.
>
> Here is my code:
>
> protected Connection lookupJNDIConnection(final String resource) {
>         InitialContext ic = null;
>         try {
>             System.out.println("will InitialContext");
>             ic = new InitialContext();
>             System.out.println("lookup nach comp/env");
>             Context envContext = (Context) ic.lookup("java:/comp/env");
>             System.out.println ("lookup.");
>             DataSource ds = (DataSource) envContext.lookup(resource);
>             System.out.println("return getconnection.");
>             return ds.getConnection();
>
>         } catch (Exception e) {
>             e.printStackTrace();
>             return null;
>         }
>     }
>
> I can see the out.println("return getconnection.") but the out.printlnafter that, in the method which calls the this method,  are not visible.
>
> And for every sql statement I perform a lookup, get the connection,
> perform the sql statement and then close the connection. Has anyone an idea
> what the problem is?
>
> Thanks in advance.
>
> --
> mfg Hans Sowa
> mailto:hanssowa@gmail.com




--
mfg Hans Sowa
mailto:hanssowa@gmail.com