javax.naming.InitialContext package has a method bind(name, object) used to add entried to a directory. here is the code that will do the needful.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import javax.naming.*;
import javax.naming.directory.*;
public class AddEntries
{
final String INITIAL_CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory";
Hashtable htbEnvironment = new Hashtable();
//DirContext to connect to Directory.
DirContext objDirCtx = null;
public AddEntries()
{
htbEnvironment.put( Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
htbEnvironment.put( Context.PROVIDER_URL, "ldap://10.10.10.10:389");
htbEnvironment.put( Context.SECURITY_PRINCIPAL, "userid" );
htbEnvironment.put( Context.SECURITY_CREDENTIALS,"password");
objDirCtx = new InitialDirContext(htbEnvironment);
}
public void addToDirectory()
{
// This is the object to be added to the directory. This class implements DirContext.
DirectoryObject objDirObject = new DirectoryObject();
try
{
objDirCtx.bind( "cn=object1,ou=blah,o=blah1", objDirObject );
System.out.println("Directory Object added successfully");
}
catch(Exception objExcep)
{
System.out.println("Got Exception While Adding");
}
}
}
[ April 17, 2002: Message edited by: kiran nori ]