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.
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:
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>
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.
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.