1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public static void main(String[] args) {
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap:///o=JNDITutorial");
try {
//DirContext ctx = new InitialDirContext(env);
Context ctx = new InitialContext(env);
// Perform the bind
ctx.bind("cn=Favorite Fruit", "Fruit");
// Check that it is bound
Object obj = ctx.lookup("cn=Favorite Fruit");
System.out.println(obj.toString());
// Close the context when we're done
ctx.close();
} catch (NamingException e) {
System.out.println("erreur "+e.getMessage());
}
} |