1. Configure the datasource with a unique name(JNDI name). 2. Write client side code to lookup for the datasource by the name using JNDI API
-->Configuring datasource varies from one server to the other. You have to refer to your server documentation for that.
-->JNDI is a platform independent way for looking up objects on a network. For this we need to obtain the InitialContext. Obtaining InitialContext differs from where we are using it for lookup. That is if we are looking up a datasource object that are part of the same J2EE application then we can create the InitialContext as below
The HashTable entry passed should provide 4 entries
1.Context.INITIAL_CONTEXT_FACTORY -- specifies which initial context factory to use when creating InitialContext. 2.Context.PROVIDER_URL -- The url of the server where the datasource is configured 3.Context.SECURITY_PRINCIPAL -- The username that will be used to authenticate the application client 4.Context.SECURITY_CREDENTIAL -- The password that will be used to authenticate the application client
Once the context object is obtained you can look up the datasource object by its unique name which was configured in step 1 as follows
thank you kamesh for your lengthy reply however I have the same problem with creating a data source. you mentioned the first step was to configure the data source with a unique name(JNDI name). can you explain how to do that please? thanks in advance