This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Transfer Learning for Natural Language Processing (MEAP) and have Paul Azunre on-line!
See this thread for details.
Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

How tp use SearchFilter with JNDI

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
ERROR:

Search.printSearchEnumeration(answer);
here

code:
--------------------------------------
import javax.naming.*;
import javax.naming.directory.*;

import java.util.Hashtable;

/**
* Demonstrates how to perform a search by specifying a search filter
* and default search controls. Functionally identical to SearchRetAll.java.
*
* 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.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
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 = ctx.search("ou=People", filter, ctls);

// Print the answer
search.printSearchEnumeration(answer);

// Close the context when we're done
ctx.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
============================================

how could i achive this..

bye..
Raga
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Oliver
 
And inside of my fortune cookie was this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic