Java DirContext modify attribute

Description

Java DirContext modify attribute

import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;

public class Main {
   public static void main(String args[]) {
      try {//ww  w . jav  a2  s .  com
         DirContext ctx = new InitialDirContext();
         Attributes attrs = new BasicAttributes(true);
         attrs.put(new BasicAttribute(args[1], args[2]));
         ctx.modifyAttributes(args[0], DirContext.ADD_ATTRIBUTE, attrs);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}



PreviousNext

Related