• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to resolve javax.naming.NoInitialContextException while using jndi to access datsource

 
Rajiv KumarRai
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I have configured the datasource on Weblogic server 11g.
When I execute this code I get the following error

javax.naming.NoInitialContextException: 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
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at Test4.main(Test4.java:33)

Please help me on how to resolve the above error

Thanks
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Refer this - https://docs.oracle.com/cd/E15523_01/apirefs.1111/e13941/weblogic/jndi/WLInitialContextFactory.html

generally works when you try access the Context from within a servlet or any class that is deployed as EAR/WAR on the server itself.

In you case, you are trying to access JNDI tree from another JVM and hence it needs to know where to look for the JNDI tree.

Regards,
Amit
 
Rajiv KumarRai
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I included the code snippet for InitialContext in my class.

Now when i run the code am getting the following output

User: root, failed to be authenticated.
null
Vendor Error Code: 0


When i run the same code without using datasource deployed on weblogic , it is able to connect
Hence its not the issue of authentication

I suppose it may be some issue with datasource configuration

While creating datasource I have given the machine name as localhost

Is it correct or I need to give IP address

 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
When i run the same code without using datasource deployed on weblogic , it is able to connect
Hence its not the issue of authentication


I think you really need to make sure if this is the case.

The documentation says -
If you don't set a principal and password, the default is to use guest/guest.
. It may be the case that you cannot access your weblogic JNDI tree with this credentials.

I would suggest you create a servlet and try accessing the DataSource using the JNDI lookup and see if it works. Please note, you do not have to pass the Hashtable with environment properties in this case.
If you can access the datasource and get the connection this(i.e. Servlet) way then we can be sure that the problem you are facing is related to accessing JNDI tree in weblogic from standalone client.

Regards,
Amit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic