• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to do JNDI lookup?

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am having a JNDI named as jdbc/raDataSource.Now how to do the JNDI lookup??HOw will my application get the datasource which I have created?Also,what does the following mean: "java:comp/env/jdbc/raDataSource"??Where&in which class of my app will I write the code for the JNDI lookup?
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To do a JNDI lookup you have to aquire the naming context and use that to access any resource.

Example:


 
Anuj Singh
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Vijitha for the reply.What does this mean:java:comp/env?Anyways..moreover now how will I tell the webapp abt the datasource?Is it in the web.xml smthg like dis:
<res-ref-name>jdbc/raDataSource</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>
Also,in which part of my code will I write the code for JNDI lookup?

Thanks
Anuj
 
Sheriff
Posts: 7138
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The java:comp/.... means the JNDI name for a particular resource, as for here, it is used for the data source. And your XML structure is correct for configuring a datasource to be used with JNDI, but that is 'not' to be used in web.xml descriptor. You need a separate descriptor like ejb-jar.xml (which will be deployed in the EJB container) to use this XML structure. However, with EJB 3.0, you don't need to use these XML configuration or even looking up for JNDI, because you can use annotations instead.

Devaka
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does comp/env also work with windows?? my app ran under jboss. and in glassfish i managed to get it deployed too. even my stateless session beans work. but i am not allowed to use DI for stateful session beans. so I would have to use lookup. But lookup works different in Glassfish than in JBoss Some "full" example would be great. I already added some ConnectionPool successfuly and some jdbc/mydb connection resource. The only thing that i think is missing is the correct JNDI lookup
 
Beware the other head of science - it bites! Nibble on this message:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic