• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Difference between resource-ref and env-entry

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
In my EJB i get the databse connection using this code
<env-entry>
<env-entry-name>poolname</env-entry-name>
<env-entry-type>java.lang.String </env-entry-type>
<env-entry-value>MyConnectionPool</env-entry-value>
</env-entry>
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
<resource-ref>
<res-ref-name>MyconnectionPool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Can any one tell me the diffrence between the 2 approaches.
thanks in advance
Hari
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
kiran
 
A feeble attempt to tell you about our stuff that makes us money
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic