[jboss-user] [JNDI and Naming] - Looking for standard jndi/jdbc java connection syntax
bwalker55
do-not-reply at jboss.com
Tue Oct 6 19:12:03 EDT 2009
Deploying java servlet code on jBoss for the first time and am having trouble with jndi/jdbc database connection.
Code from long running Tomcat/Resin deployments look like:
Context init = new InitialContext();
| Context ctx = (Context)init.lookup("java:comp/env");
| DataSource ds = (DataSource) ctx.lookup("jdbc/" + dbName); // dbname defined in Tomcat server.xml
With jBoss the above code gives: javax.naming.NameNotFoundException: jdbc not bound error.
As per http://www.jboss.org/community/wiki/WhyDoIGetNameNotFoundException
I have changed the last line to:
DataSource ds = (DataSource) ctx.lookup("java:/" + dbName); // dbname defined in *-ds.xml for jBoss
and this works.
However, I would like to find a solution that works on both servers. I've looked through the JNDI Wiki and FAQ as suggested in the Sticky, but there's nothing obvious jumping out at me as to what I need to do.
Thanks, Bob.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4259007#4259007
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4259007
More information about the jboss-user
mailing list