Creating an Initial Context to a Directory - Java JNDI

Java examples for JNDI:Context

Description

Creating an Initial Context to a Directory

Demo Code

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;

public class Main {
  public static void main(String[] argv) {
    String url = "ldap://localhost/o=JNDITutorial";
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);
    try {/* w  ww . j a v a 2s  . c o m*/
      DirContext ctx = new InitialDirContext(env);
    } catch (NamingException e) {
    }
  }

}

Related Tutorials