DirContext.REPLACE_ATTRIBUTE : DirContext « javax.naming « Java by API






DirContext.REPLACE_ATTRIBUTE

 


import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.ModificationItem;

public class Main {
  public static void main(String[] argv) throws Exception {
    ModificationItem[] mods = new ModificationItem[3];

    mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("mail","g@w.com"));

    mods[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("number","5555"));

    mods[2] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute("jpeg"));
    String url = "ldap://localhost/o=JNDITutorial";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);

    DirContext ctx = new InitialDirContext(env);
    ctx.modifyAttributes("cn=Name, ou=People", mods);
  }
}

   
  








Related examples in the same category

1.DirContext.ADD_ATTRIBUTE
2.DirContext.REMOVE_ATTRIBUTE
3.DirContext: getAttributes(String name)
4.DirContext: getAttributes(String name, String[] attrIds)
5.DirContext: search(String name, String filter, SearchControls cons)