public static void main(String[] args) { // set up environment to access the server Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://" + ldapServerName + "/" + rootContext); env.put(Context.SECURITY_PRINCIPAL, rootdn); env.put(Context.SECURITY_CREDENTIALS, rootpass); try { // obtain initial directory context using the environment DirContext ctx = new InitialDirContext(env); // create some random number to add to the directory Integer i = new Integer(28420); System.out.println("Adding " + i + " to directory..."); ctx.bind("cn=myRandomInt", i); i = new Integer(98765); System.out.println("i is now: " + i); i = (Integer) ctx.lookup("cn=myRandomInt"); System.out.println("Retrieved i from directory with value: " + i); } catch (NameAlreadyBoundException nabe) { System.err.println("value has already been bound!"); } catch (Exception e) { System.err.println(e); } }