Creating an Initial Context to a Directory This example uses the JNDI/LDAP service provider to connect to an LDAP server on the local machine. 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 { DirContext ctx = new InitialDirContext(env); } catch (NamingException e) { }