Home Help Java C JNDI Context
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

JNDI Context

Advertisement
Like JDBC (Java Database Connectivity), JNDI is not a service, but a set of interfaces that allows applications to access many different directory service providers using a standardized API.

JNDI Context 

     

Like JDBC (Java Database Connectivity), JNDI is not a service, but a set of interfaces that allows applications to access many different directory service providers using a standardized API. The deployed enterprise beans in EJB have an environment-naming context that can be accessed using the JNDI API. It also accesses an enterprise resource such as a data source or JavaMail session in a distributed computing environment.

 To do this, you must first obtain the initial context that contains the resource (a Java object).

The java.naming.Context interface provides methods for retrieving and updating this name-to-object binding environment in which each name passed as an argument to a Context method is relative to that context. A name parameter may never be null.

 

Storing and retrieving objects from a JNDI namespace is quite straightforward. You first obtain a JNDI naming context and then use the bind() and lookup() methods to store and retrieve objects, as shown below:


 Store and retrieve objects from a default JNDI namespace

import javax.naming.*;
public void createName() throws NamingException {
Context context = new InitialContext();
context.bind("java:comp/env", "MyApp");
}
public String getName() throws NamingException {
Context context = new InitialContext();
return (String) context.lookup("java:comp/env");
}


Read more at:

http:/www.roseindia.net/software-tutorials/detail/3658

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 16, 2009

Ask Questions?    Discuss: JNDI Context   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Andres
March 27, 2013
thank you!

i never had seen an explanation so concise! excellent! it clarified all my doubts!!
DMCA.com