You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kevin HaleBoyes <kz...@yahoo.com> on 2003/03/07 21:05:42 UTC

faking a JNDI context

First off, Craig, I hope it is not inappropriate for me to CC you
directly.

There was a discussion many months ago, on this list, about the
benifits of using the JNDI mechanism for getting DataSource objects.
The basic code is as follows:

        Context initCtx = new InitialContext();
        Context envCtx = (Context)initCtx.lookup("java:comp/env");
        DataSource ds = (DataSource)envCtx.lookup("jdbc/Db");
        Connection conn = ds.getConnection();

This requires the proper setup in the server.xml and web.xml
configuration files.

I've been using this for some time now and it works great.

In that discussion, Craig mentioned how to use that same code when
outside of the (Tomcat) servlet environment, for example in a 
stand-alone application.  IIRC, the "trick" was to instantiate
a DataSource and to put it into the proper context.  Craig even gave
sample code to do that.

I'm after that code.  I've searched the archive but that has proved
to be difficult in that I can't narrow down the search adequately.

Can anyone point me to that discussion in the archives or provide
this sample code?

Thanks,
Kevin.


__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org