Loading
JNDI Look Up

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  What is JNDI ?


Ans)

The Java Naming and Directory Interface (JNDI) is an application programming interface
(API) for accessing different kinds of naming and directory services. JNDI is not
specific to a particular naming or directory service, it can be used to access many
 different kinds of systems including file systems; distributed objects systems
 like CORBA, Java RMI, and EJB; and directory services like LDAP, Novell NetWare, and NIS+.

JNDI is similar to JDBC in that they are both Object-Oriented Java APIs that
 provide a common abstraction for accessing services from different vendors.
 While JDBC can be used to access a variety of relational databases,
 JNDI can be used to access a variety of of naming and directory services.

Weblogic JNDI Look Up:

Two steps , get obtain the InitialContext(), lookup() or Register by using Bind();

Context ctx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,
"t3://localhost:7001");

try {
ctx = new InitialContext(ht);
ctx.bind("my_object", MyObect);
ServiceBean bean = (ServiceBean)ctx.lookup("ejb.serviceBean");
}
catch (NamingException e) {
// a failure occurred
}

Spring JNDI tag:
   <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
        <property name="environment">
            <props>
                <prop key="java.naming.factory.initial">
    com.sun.jndi.fscontext.RefFSContextFactory</prop>
                <prop key="java.naming.provider.url">file:c:/temp</prop>
            </props>
        </property>
    </bean>
    <bean id="jndiDataSource" class="
 org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate">
          <ref bean="jndiTemplate"/>
        </property>
        <property name="jndiName">
              <value>MYCONNECTIONKEY</value>
        </property>
      </bean>


Web Sphere JNDI :

 Properties p = new Properties();
 p.put("org.omg.CORBA.ORBClass","com.sun.CORBA.iiop.ORB");

    p.setProperty( javax.naming.Context.INITIAL_CONTEXT_FACTORY,
    "com.ibm.websphere.naming.WsnInitialContextFactory" );

    p.setProperty( "java.naming.provider.url", "iiop://HOSTNAME:PORT" );
   
    String connectionfactoryjndi="jms/testQCF";
    String sendQueueName="jms/destOutboundQ";

    Context jndiContext = new InitialContext();
    jndiContext = new InitialContext( p );



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

JNDI Look Up


JNDI Look Up

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free