Reputation: 852
I am new to JNDI
, I know something about Java Naming service, we can use it for binding and unbinding objects with user friendly names. But I am trying to learn about JNDI Directory service, I tried in internet to know about JNDI
Directory service, they tried to explain that we can store attributes, retrieve them and search objects by using attributes.
But I am not able to analyze the actual concept of JNDI
Directory service.
If any one can explain me, what is directory service in JNDI
with some real time example, I feel happy.
I tried oracle documentation also, so please don't suggest me the documentation again.
Upvotes: 4
Views: 937
Reputation: 852
Yeah, Finally I got solution to my question,
What is Directory service exactly and compared with Naming service of JNDI?
Answer: By using JNDI naming service we can store objects with user friendly name in centralized location called JNDI server.
We can retrieve them in any java application with out need to recreate them in individual application.
This is helpful when ever you want to get database connection in your application instead of creating database connection in your application you can easily get the ready made connection object from the JNDI server by using JNDI's Naming service.
This is just like, instead of purchasing all books yourself, you can go to book library and get the book you want from the library.
Coming to JNDI's directory service, by using directory service you can store objects with user friendly names, along with object you can store some additional information also. This additional information you can store like key value pairs also called as attributes.
For example, from JNDI server you want to get ready made connection object, but there are lot of connections objects are present in JNDI, one connection is pointing to MYSQL
database another is pointing to ORACLE
database, now how to know which connection object is pointing to MYSQL
which is pointing to ORACLE
.
For this purpose when ever we are storing connection object in database, along with connection object we can store some additional attributes also, which are indicating the database name to which the connection object is pointing to. EX of Attribute is databaseName=ORACLE
for ORACLE
database connection object. and databaseName=MYSQL
for MYSQL
connection object.
This is the exact use of JNDI
directory service.
You can learn more from here
Here I need to thank Mr.Deepanshu Bedi also who hepled me a lot to get this answer myself.
Upvotes: 3
Reputation: 1530
JNDI is the Java Naming and Directory Interface. It's used to separate the concerns of the application developer and the application deployer. When you're writing an application which relies on a database, you shouldn't need to worry about the user name or password for connecting to that database. JNDI allows the developer to give a name to a database, and rely on the deployer to map that name to an actual instance of the database.
For example, if you're writing code that runs in a Java EE container, you can write this to get hold of the data source with JNDI name "Database":
DataSource dataSource = null;
try
{
Context context = new InitialContext();
dataSource = (DataSource) context.lookup("Database");
}
catch (NamingException e)
{
// Couldn't find the data source: give up
}
Note there's nothing here about the database driver, or the user name, or the password. That is configured inside the container.
An introduction to directory services
A directory service provides a way to manage the storage and distribution of shared information. Such information can range from the email addresses and phone numbers of a company's employees, to the IP addresses and print capabilities of a department's printers, to the configuration information for a suite of application servers.
A directory service manages a directory of entries. A directory entry can refer to a person, place, service, or almost any other concrete object or abstract concept. An entry also has attributes associated with it; an attribute consists of a name or identifier and one or more values. These attributes describe the entry, and the exact set of attributes depends on the type of the entry. For example, the entry for an individual might have the following attributes (note the two email addresses):
Name: John Doe
Address: 123 Somewhere Street
Email: [email protected]
Email: [email protected]
Directory services are simple databases. Like their relational cousins, many common directory services provide search and filter functionality. Instead of locating an entry only by name, these directory services allow you to locate entries based on a set of search criteria.
Naming services and directory services are logical partners. In fact, most existing products provide both sets of functionality. Naming services provide name-to-object mapping, and directory services provide information about the objects and tools for searching for them.
best explanation about JNDI DIRECTORY SERVICES on internet
Upvotes: -1