Java DirContext add attribute

Description

Java DirContext add 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 .  j a va2 s  .  c  o m
         DirContext ctx = new InitialDirContext();
         Attributes attrs = new BasicAttributes(true);
         attrs.put(new BasicAttribute("objectclass", "organization"));
         ctx.bind(args[0], new String("An organization"), attrs);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}



PreviousNext

Related