aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes How to use JNDI for database connectity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to use JNDI for database connectity" Watch "How to use JNDI for database connectity" New topic
Author

How to use JNDI for database connectity

Sachin Yewale
Greenhorn

Joined: Feb 02, 2012
Posts: 21
Hi,
I want to know how to use JNDI for db connectivity in java. In one my project (done by other) It is used, but i dont understand some code such as what is cotext parameter? code is

i tried to search that but did not understand actual meaning of this ,
Can anyone explain me ?



Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

Have you read the javadoc for Context and InitialContext?

http://docs.oracle.com/javase/1.4.2/docs/api/javax/naming/Context.html


Thanks & Regards, Sumeet
SCJP 1.4, SCWCD 5, LinkedIn Profile
Sachin Yewale
Greenhorn

Joined: Feb 02, 2012
Posts: 21
All naming service operations are performed on some implementation of the Context interface. Therefore, you need a way to obtain a Context for the naming service you are interested in using.

The javax.naming.IntialContext class implements the Context interface, and provides the starting point for interacting with a naming service.

When you create an InitialContext, it is initialized with properties from the environment. JNDI determines each property's value by merging the values from the following two sources, in order such as:
•The first occurrence of the property from the constructor's environment parameter and (for appropriate properties) the applet parameters and system properties.
•All jndi.properties resource files found on the classpath.


Properties required for InitialContext to work with Jboss are
>Context.INITIAL_CONTEXT_FACTORY : The name of environment property InitialContext to use with value "org.jnp.interfaces.NamingContextFactory" (this is for Jboss of not given javax.naming.NoInitialContextException will be thrown)
>Context.PROVIDER_URL : name of environment property for specifying location of JbossNS Service Provider

http://books.google.co.in/books?id=26iZd0RYNqIC&pg=PA127&dq=org.jnp.interfaces.NamingContextFactory&hl=en&sa=X&ei=G-vtT6-GNYblrAfE_bi9DQ&redir_esc=y#v=onepage&q&f=false
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use JNDI for database connectity