What is the use of JNDI?

Discussions

General J2EE: What is the use of JNDI?

  1. What is the use of JNDI? (3 messages)

    Hi..All Techies.

    I am newbie in EJB. I want to know why we use JNDI ?? As it is written in book that it is for Name to object binding in EJB ? what acutally it does i m not clear

    So please let me know whether it is used for Datasource binding or what ??

    Thanks in advance

    Regards
    Chintan

    Threaded Messages (3)

  2. What is the use of JNDI?[ Go to top ]

    JNDI is an abstarct specification like JDBC. It is implemented by other software vendors.

    JNDI provides the way by which one can the objects binds in context. It uses directory kind of structure to bind the objects which is accesible by passing simple string showing logical directory structure eg. "jdbc/DB1".

    Implementation of JNDI first parse the string passed then fetch the object stored int the context from the location requested by String.
  3. What is the use of JNDI?[ Go to top ]

    Thanks..right now i am reading thru book and found code for 0bject-name binding i am putting this code here and please tell me what actually it does

    Properties prop = new Properties();

    prop.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
    prop.put(Context.PROVIDER_URL,"localhost:1099");
    try{
    InitialContext jndicontext = new InitialContext(prop);
    Object ref = jndicontext.lookup("search");
            SearchHome home = (SearchHome)PortableRemoteObject.narrow(ref,SearchHome.class);
            Search searchbean = home.create();
    //some code

    }

    so what excatly this means..

    Regards
    Chintan
  4. What is the use of JNDI?[ Go to top ]

    Hi,

    I'm trying to explain it a bit:

    > Properties prop = new Properties();
    >

    This Properties object will contain the jndi properties with which the jndi-service will work.

    > prop.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
    > prop.put(Context.PROVIDER_URL,"localhost:1099");

    Here you tell the jndi-service with which factory the InitialContext is going to be built and where the service can look after the InitialContext.

    > try{
    > InitialContext jndicontext = new InitialContext(prop);
    > Object ref = jndicontext.lookup("search");

    Here you instantiate a new InitialContext with the specified properties above.

    > SearchHome home = (SearchHome)PortableRemoteObject.narrow(ref,SearchHome.class);
    > Search searchbean = home.create();

    Now you use the reference object you got via the lookup to create an instance of a bean you can work with.

    > //some code
    >
    > }
    >
    > so what excatly this means..

    I hope my explanations help you and are correct. Any corrections are welcome.

    Peter

    >
    > Regards
    > Chintan