-
1. Re: Using jndi from a web project
mornblues Jul 22, 2009 5:33 PM (in response to mornblues)I'm sorry, the error message is actually:
java.lang.Exception: Datasource is not builded. JNDI pool name is invalid or application server JNDI database connection pool service is invalid. Verify your database settings.
But all the rest still stands. -
2. Re: Using jndi from a web project
peterj Jul 22, 2009 5:49 PM (in response to mornblues)If you set use-java-context to true (the default), then the datasource name is actually "java:myname" based on your example (you can check with JNDIView to verify this).
However, you cannot connect to the java:/nyname name from a remote client - only apps deployed within JBoss AS can access things in the "java:" namespace.
I know that from a web app you need to provide a few configuration settings to get the connection made. First, you need to use this name:
java:comp/env/myname
then you need this entry in web.xml:<resource-ref> <res-ref-name>myname</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref>
and this entry in WEB-INF/jboss-web.xml:<jboss-web> <resource-ref> <res-ref-name>myname</res-ref-name> <jndi-name>java:myname</jndi-name> </resource-ref> </jboss-web>
-
3. Re: Using jndi from a web project
mornblues Jul 23, 2009 10:12 AM (in response to mornblues)I have tried that already, but it still doesn't work. I can't figure out why. When I first read about it (http://forums.sun.com/thread.jspa?threadID=626778) it looked like "java:myname" had to work, even without using the reference thing. So I thought the root of my problem was that I couldn't access it in the first place.
I'm out of ideas, I think I'll just make a conditional in the code so it will work on jboss and tomcat differently. -
4. Re: Using jndi from a web project
peterj Jul 23, 2009 1:29 PM (in response to mornblues)Saving possible typos that I made, what I posted is what I use for one of my apps, only the datasource name was changed. Of course, that's not to say it is the only way.