Answer Posted / rajkumar siripuram
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 = 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.
JNDI is not restricted to databases (JDBC); all sorts of
services can be given names. For more details, you should
check out the Sun tutorial on the subject.
link|flag
RAJKUMAR SIRIPURAM
| Is This Answer Correct ? | 9 Yes | 1 No |
Post New Answer View All Answers
Define EAR, WAR and JAR ?
What is stateless ejb?
What is ejb and how it works?
Enlist the changes in EJB 2.1 ?
What is the advantage of using entity bean for database operations, over directly using jdbc api to do database operations? When would I use one over the other?
Can you be deported if you are stateless?
What is the purpose of ejb in java?
What is the full form of ejb in java?
What is an ejb context?
How many enterprise beans?
What is backing bean?
What is Enterprise JavaBeans Query Language (EJB QL)?
What are the design principles for ejb?
What is bean-managed persistence?
What is an entity and its types?