wood burning stoves 2.0*
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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(TestJDBCOracleDS2.java:29)

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:

BLOG: http://leakfromjavaheap.blogspot.com
subject: Use of JNDI in Standalone java program
Similar Threads
JNDI, xxx is already bound
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