wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Difference between resource-ref and env-entry Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Difference between resource-ref and env-entry " Watch "Difference between resource-ref and env-entry " New topic

Difference between resource-ref and env-entry

Hari babu
Ranch Hand

Joined: Jun 25, 2001
Posts: 208
Hi all,
In my EJB i get the databse connection using this code
<env-entry-type>java.lang.String </env-entry-type>
and i get the database connection using the code below
initCtx = new InitialContext();
String pool = (String) ((Context)initCtx.lookup("java:comp/env/poolname");
DataSource ds = (javax.sql.DataSource)initCtx.lookup(pool);
I use the above "ds" to get the database connection
Also i read that we can get the connection by using <resource-ref> as shown below
Can any one tell me the diffrence between the 2 approaches.
thanks in advance
Kiran Kumar
Ranch Hand

Joined: May 18, 2001
Posts: 107
references is used when an alias name is required to access a particular resource. like the jndi name of an ejb session bean is "ejb/mybean" but the bean has to be accessed as "mysessionbean", in this kind of a situation u give a reference and use the second name to access the bean. likewise for the resource references.
env-entry is like having a static variable in the bean class. since having a static variable in a bean is not good practice, u can make use of the env-entry to get a value.
hope this helps

Thanks<br /> <br />Kiran <br /> <br />SCEA, SCJP 1.4,<br /> <br />"First they ignore u, then they laugh at u, then they fight u, <br />then u will win<br /> <br />Mahatma Gandhi"
I agree. Here's the link: http://aspose.com/file-tools
subject: Difference between resource-ref and env-entry
Similar Threads
Configuring Mail Session for Orion
DSN name not found error with TOMCAT5.5.7
Database connectiivity Error using DataSource
Databse Connectivity Error
JNDI javax.naming.NamingException