To get DataSource object of a connection pool which I cerated in weblogic 7.0, I can do JNDI loop in two ways...
1.DataSource ds = (DataSource) ic.lookup("sampleConnPool");
where "sampleConnPool" is the JNDI name of the pool which i created....
2. private String dbName = "java:comp/env/jdbc/sampleConnPool";
where "java:comp/env/jdbc/sampleConnPool" is having entry in ejb-jar.xml
DataSource ds = (DataSource) ic.lookup(dbName);
can somebody tell me what is the difference between two ways of doing JNDI lookup...
Although both approaches are valid there are some slight differences. The first approach looks up the datasource directly in the jndi tree while the second approach goes through the ejb enc to look up the datasource. When resource references are declared in ejb, those references are local only to the bean they are declared in. So the reference declared in the second approach is only visible to the ejb declaration that contains it. This provides a layer of indirection which may be useful for resolving conflicts.
Thanxs, Can, u explain the statement in detail "This provides a layer of indirection which may be useful for resolving conflicts"....
There's a 2nd xml file that's appserver specific and while by default you'll have the same names there, it allows you the option of having a generic name in the code java:comp/env/jdbc/MyDataSource but at deploy time, specify exactly which 'real' datasource that it linked to.
How much this is of use comes down to how generic/re-usable your bean/environment needs to be...
interesting to know the diff. in the two approaches...
we can use jndi.properties file to describe:
to make the code generic..