File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes How tp use SearchFilter with JNDI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How tp use SearchFilter with JNDI" Watch "How tp use SearchFilter with JNDI" New topic

How tp use SearchFilter with JNDI

raga menon

Joined: May 08, 2007
Posts: 8
Hi all,

i have to search the entry and display the enties. here i used the search
filter for that, when i try to compile the program am getting the error.


import javax.naming.*;

import java.util.Hashtable;

* Demonstrates how to perform a search by specifying a search filter
* and default search controls. Functionally identical to
* usage: java SearchWithFilterRetAll
class SearchWithFilter
public static void main(String[] args) {

// Set up the environment for creating the initial context
Hashtable env = new Hashtable(11);
env.put(Context.PROVIDER_URL, "ldap://localhost:2389/dc=example,dc=com");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
env.put(Context.SECURITY_CREDENTIALS, "secret");

try {
// Create initial context
DirContext ctx = new InitialDirContext(env);

// Create default search controls
SearchControls ctls = new SearchControls();

// Specify the search filter to match
// Ask for objects with attribute sn == Geisel and which have
// the "mail" attribute.
String filter = "(uid=user.10)";

// Search for objects using filter
NamingEnumeration answer ="ou=People", filter, ctls);

// Print the answer

// Close the context when we're done
} catch (Exception e) {

how could i achive this..

Oliver Kamps

Joined: May 15, 2007
Posts: 18
Hi Raga,

code is much easier to read if you put it into code tags (see the buttons below the edit box).

You could have saved some time by providing the error message in your question. My compiler says:

"search cannot be resolved"

You have not declared the variable "search" anywhere in your code.

Hope this helps,
I agree. Here's the link:
subject: How tp use SearchFilter with JNDI
jQuery in Action, 3rd edition