Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

problem in LDAP search

I am having problem in running the below code, can someone pls help me out with it ? It either doesn't return anything or gives error code 32.

import javax.naming.*;

import javax.naming.ldap.*;

import java.util.*;

import javax.naming.directory.*;

public class ldapdemo {

public static void main(String[] args) {

try {

Hashtable env = new Hashtable();

env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");

env.put(Context.PROVIDER_URL, "LDAP://dewdfx1b1:389");

LdapContext ldapctx = new InitialLdapContext(env, null);

Attributes matchAttrs = new BasicAttributes();

matchAttrs.put("uid","I028949");

String [] attrIDs = {"cn","mail"};

NamingEnumeration answer = ldapctx.search("o=SAP", matchAttrs, attrIDs);

while(answer.hasMore()) {

SearchResult sr = (SearchResult)answer.next();

Attributes resultAttrs = sr.getAttributes();

String username = resultAttrs.get("cn").getID();

String mail = resultAttrs.get("mail").getID();

System.out.println("username="+username);

System.out.println("mail="+mail);

}

} catch (NamingException e) {

System.out.println(e.getMessage());

return;

}

}

}

Not what you were looking for? View more on this topic or Ask a question