Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

JNDI

Posted on 2005-04-22
10
Medium Priority
?
666 Views
Last Modified: 2013-11-24
Hi,

Can anyone tell me the concept of JNDI in idiot please? What are the differences between naming services and directory services in JNDI itself?

On scenario.
Last time, I was developing J2EE Web Application. I have DataSource on my Tomcat and I bind it in the context. Then my EJB is also bound into JNDI for each of the session bean (Is it? I forgot about it :D). My questions are are these things (DataSource and EJB JNDI) are living together in one place (JNDI)? What would happen if the names are accidentally same? How does JNDI detect it?

Can my J2SE app call JNDI? I believe not but to download dbcp.

Thanks you.

Regards
Dave
0
Comment
Question by:suprapto45
  • 7
  • 3
10 Comments
 
LVL 15

Expert Comment

by:aozarov
ID: 13848380
>> concept of JNDI
A lookup service based on key to identify the request and a value (stored object)

>> What are the differences between naming services and directory services in JNDI itself?
directory services provides attributes on their stored objects.

see: http://java.sun.com/products/jndi/tutorial/

>> What would happen if the names are accidentally same?
If you bind something with a name that already exists you will get an exeption unless you called rebind instead of bind.

>> Can my J2SE app call JNDI?
Sure, why not (it is part of the j2se sdk since 1.4), you just need a naming service running.
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13848383
Some addon:

>> directory services provides attributes on their stored objects.
To make it clear, Directory serice is an extension of a naming service.

>> If you bind something with a name that already exists you will get an exeption unless you called rebind instead of bind.
And in the tomcat case, probably bind and not rebind is called, so you will get NamingException if that happens.
0
 
LVL 16

Author Comment

by:suprapto45
ID: 13848408
Hi aozarov,

"directory services provides attributes on their stored objects."

What does it mean? Can you explain more?

and I am quite confused in are these things (DataSource and EJB JNDI) are living together in one place (JNDI)?

Regards
Dave

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 15

Accepted Solution

by:
aozarov earned 1200 total points
ID: 13848442
>> and I am quite confused in are these things (DataSource and EJB JNDI) are living together in one place (JNDI)?
They are not.
Think of jndi as a repository of links of where to find the other J2EE services. (like yellow pages).
It does not really store the EJB but rather store a proxy to the EJB home.
It does not really store the connection pool but rather store the proxy to the data source that is connected to the pool.
You can create your own rmi service and bind your stub (your rmi service proxy) to the jndi with a specific name.

>> What does it mean? Can you explain more?
If you look at the Directory API http://java.sun.com/j2se/1.4.2/docs/api/javax/naming/directory/DirContext.html you will see
that it extends Context (the standard naming service api) and add to it method to get attributes that were associated with
the object that was bound under that name.
0
 
LVL 16

Author Comment

by:suprapto45
ID: 13848445
mmm...thanks.

will Context make any difference in storing JNDI? Since if I am not mistaken, if I want to create DataSource in Tomcat, I need to set it in Context.

Regards
Dave
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13848479
>> I need to set it in Context
This just happened to have the same name :-))
The context you are talking about is Tomcat way of defining a web application -> http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/context.html
and this linke explains how to add to it the datasource http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13848493
The link I gave you above is one of the most complete tutorials available on JNDI
But if you are looking for a good and quick tutorial then you can have a look at:
http://www.javaworld.com/javaworld/jw-01-2000/jw-01-howto_p.html
0
 
LVL 16

Author Comment

by:suprapto45
ID: 13848536
Thanks aozarov.

Regards
Dave
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13849586
:-)
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13882745
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 19 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question