• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception: Name [jdbc:/comp/env] is not bound in this Context

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I am using tomcat 7.x and trying to do JNDI lookup and get DataSource instance. When i try to use Context's lookup(String name) method it is not working. I am gettingWhen I try to do the same with @Resource(name = "jdbc/mytest") I am able to get the DataSource instance and my application is working fine. Why is this problem occurring?

I declared the resource in server.xml file asand a resource-ref in my web.xml like thisBefore using @Resource I tried putting the Resource in context.xml file under META-INF folder also. But everything failed. I read here http://www.coderanch.com/t/496324/Tomcat/jdbc-JNDI-name-causes-Tomcat that we have to check "Publish module contexts to separate xml files". I did this, even it dint work. Then after using @Resource I unchecked this and it worked.

Why am I not able to use Context's lookup(String name) method?

Thank you all in advance. Good day.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a basic problem in the JNDI lookup name. It's not "jdbc:/comp/env", it's "java:comp/env". Or, more fully:

java:comp/env/jdbc/mytest
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Mr. Tim.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic