This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I need a good example of a JNDI lookup for an oracle database. This is the code I have for getting the datasource however I still need to create the InitialContext. What do I put into the env hashtable?
By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
In JBoss, the DataSource definition is deployed as a *-ds.xml file in the server's deploy directory.
Are you trying to do this lookup from client code, or from within an application deployed on the server?
Joined: Nov 02, 2000
From an application deployed on the server. It looks as though I have the JNDI names bound to the database. I know this because when JBoss comes up, it shows that in the console log. BUT when I do a lookup on the names it returns an exceptiom and gives me this.
When I step through the code and into the InitialContext class.. it fails on this method...
Specifically this line...
which in turn goes here..
environment is equal to an empty hashtable w/no key/value pairs in it and so answer is equal to null and thus returns null. And thus throws an exception. Specifically it throws this exception...
[ January 19, 2007: Message edited by: Dale DeMott ]
You need to specify the naming factory you are using. For JBoss4 that will be java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory. You'll also need the to include the URL for the naming provider, probably java.naming.provider.url=jnp://localhost:1099.
However, if you need to specify these environment values this suggest you are trying to lookup the DataSource from a remote client. If you are be aware this is only possible from JBoss4 and you need to configure your DataSource to allow this with <use-java-context>false</use-java-context> in the DS file.