Java DirContext modify via ModificationItem

Description

Java DirContext modify via ModificationItem

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 args[]) {
      try {// w w w. j a  v a  2  s . c  o  m
         DirContext ctx = new InitialDirContext();
         ModificationItem[] mi = new ModificationItem[3];
         mi[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE,
               new BasicAttribute("description", "new"));
         mi[1] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
               new BasicAttribute("description", "new new"));
         mi[2] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute("postalCode"));
         ctx.modifyAttributes(args[0], mi);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}



PreviousNext

Related