This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

NamingException was thrown

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all .,

I am trying to execute a simple JNDI example. The code is as shown below.

try{
Context initialContext=new InitialContext();
initialContext.bind("name", "Suresh Sai");
Object stringObject= initialContext.lookup("name");
System.err.println("the string object..... "+stringObject.toString());
}
catch (NamingException ne)
{
System.err.println("naming exception was thrown... "+ne.getMessage());
}


Its compiling,But while running its throwing NamingException ..,

Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

Is there any wrong with the code? My main aim is , to creat a name for an object and to access that object through that name.

Please halp me.And also suggest me some good books and resources for JNDI.

Thanks in Advance
 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. Your code uses the API, but looks like you either completely lack a provider, or you have a provider in your classpath, but you didn't configure it. Please take a look at this:
http://java.sun.com/products/jndi/tutorial/basics/prepare/initial.html
which tells you how to basically configure one. You can do it with a Hashtable, or using properties files in different locations. Follow this:
http://java.sun.com/products/jndi/tutorial/beyond/env/index.html (go to the next 2 pages to learn more).
If you don't have a provider, go here:
http://java.sun.com/products/jndi/serviceproviders.html
and choose one. When I was learning about JNDI, I used File System provider and LDAP (but you need a LDAP server to use it, I used OpenLDAP).
Hope this helps.
[ December 30, 2008: Message edited by: Raf Szczypiorski ]
 
suresh sai
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raf.,

Thanks for the reply.Could you please tell me which service provider Do I need to use? There are lot of service providers ..RMI,CORBA,LDAP etc.Which one is suitable to the above code .I have already configured RMIRegistry.jar. Is this not enough?
 
suresh sai
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raf.,
Thanks for the reply.Could you please tell me what is the suitable service provider for the above code.There are lot of service providers like RMI, LDAP,CORBA etc.I have already configured RMIRegistry.jar.Is this enough?
....?
 
I once met a man from Nantucket. He had a tiny ad
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic