| Author |
Need JNDI example
|
Dale DeMott
Ranch Hand
Joined: Nov 02, 2000
Posts: 514
|
|
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)
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
What do I put into the env hashtable?
That depends on which naming provider you are using. Normally you'll find this in your Application Server documentation.
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Dale DeMott
Ranch Hand
Joined: Nov 02, 2000
Posts: 514
|
|
I'm looking to do a JNDI lookup for a JDBC connection for an Oracle 10i table. I'm using a JBoss app server. The current code I have is as follows I guess too I was wondering where I put my xml file with all my attributes for the database. Tracing through the code, it looks as though its not being found.
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
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?
|
 |
Dale DeMott
Ranch Hand
Joined: Nov 02, 2000
Posts: 514
|
|
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 ]
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
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.
|
 |
Dale DeMott
Ranch Hand
Joined: Nov 02, 2000
Posts: 514
|
|
Thanks much for your reply. Thats what I needed.
|
 |
 |
|
|
subject: Need JNDI example
|
|
|