Creating a Directory Entry in JNDI - Java JNDI

Java examples for JNDI:Context

Description

Creating a Directory Entry in JNDI

Demo Code

import javax.naming.Context;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;

public class Main {
  public static void main(String[] args) throws Exception {
    try {//from  w w  w  . j  a  v a 2  s .co  m
      // Create attributes to be associated with the new entry
      Attributes attrs = new BasicAttributes(true); // case-ignore
      Attribute objclass = new BasicAttribute("objectclass");
      objclass.add("top");
      objclass.add("extensibleObject");
      attrs.put(objclass);

      // Create the context
      Context ctx = null;
      Context entry = ctx.createSubcontext("cn=Sample");
    } catch (Exception e) {
    }
  }
}

Related Tutorials