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 Use of JNDI in Standalone java program 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 "Use of JNDI in Standalone java program" Watch "Use of JNDI in Standalone java program" New topic

Use of JNDI in Standalone java program

siddharth das
Ranch Hand

Joined: Aug 17, 2007
Posts: 124

I have code snippet

But it is showing below 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.bind(Unknown Source)
at TestJDBCOracleDS2.main(

The error comes at line ctx.bind("jdbc/dsName",ods);

The above code is in a standalone java program , no web application.

Can you please help.

Is it possibel to use JNDI in standalone java program

Thanks in Advance!!
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804

Why do you want to use JNDI in Java SE application? It is not available.

I can give you an example of obtaining a connection for in-memory H2 database:

I agree. Here's the link:
subject: Use of JNDI in Standalone java program
Similar Threads
Can't access JDBC Datasource using JNDI
Does JDBC Use Certs or CA's ?
Error code of ORA-12645 for DB connection
Oracle10g: java.sql.SQLException: Invalid Oracle URL specified
JNDI, xxx is already bound