tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Wulff <ewu...@gmail.com>
Subject Re: DataSource and initialContext.lookup("java:comp/env")
Date Sun, 07 Nov 2004 05:19:18 GMT
helpful somewhat...  at least in helping me narrow my question.  So
what is this "java:comp/env"?  What exactly is being returned based on
this string passed to lookup()?

Eric


On Sat, 06 Nov 2004 23:35:34 -0500, Frank W. Zammetti
<fzlists@omnytex.com> wrote:
> I'll give it a shot...
> 
> All JNDI resource lookups occur relative to some context.  The code you
> posted first gets the default initial context, then looks for a resource
> named "java:comp/env" relative to that default context.  It then gets a
> reference to a DataSource that exists within the context "jdbc/wms"
> relative to "java:comp/env"
> 
> You can ROUGHLY think of this the same way you do URLs... in a sense,
> the "java:comp/env" might be something like www.apache.org.  That gives
> you a starting context.  Then if you want to retrieve a particular file
> in that domain, you look it up relative to the domain (i.e.,
> www.apache.org/tomcat.htm).
> 
> Same thing here... There is a hierarchy of JNDI resources, a tree
> structure, that has an initial context as the root.  You then are in a
> sense constructing a path to your DataSource, and it might look
> something like /initial_context/java:comp/env/jdbc/wms (not exactly, but
> you get the idea).
> 
> Does that help any?
> 
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> 
> 
> 
> Eric Wulff wrote:
> > I just returned from working on a tutorial at sun which I was inspired
> > to go over based on my lack of understanding of the code snippet
> > below.  I'm trying to fully understand what's going on.  Docs state
> > that the code...
> >
> > initialContext.lookup("java:comp/env")
> >
> > returns a named object.  Best I can tell is that this is a reference
> > to a starting point in my directory... or something like that.  Is
> > anyone willing to explain what initialContext.lookup() fundamentally
> > takes care of when called?
> >
> > Context initialContext = new InitialContext();
> > Context context = (Context) initialContext.lookup("java:comp/env");
> > DataSource dataSource = (DataSource) context.lookup("jdbc/wms");
> >
> > thx
> > Eric
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
> >
> >
> > .
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
>

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


Mime
View raw message