This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can I bind datasource to java:comp/env/myName JNDI?

 
Lucas Lee
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to bind datasource to java:comp/env/myName JNDI in tomcat,
But exception occurrs.It seems I can only bind datasource to MyName but to java:comp/env/MyName.
Can anybody help me ?Thanks in advance.
 
karthikeyan Chockalingam
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assume your configuration in <TomcatHome>/conf/server.xml is like
<Resource name="jdbc/MyABCDXYZ_DS" auth="Container" type="javax.sql.DataSource" .....

use the following Java code to retrieve the datasource. Please note that there are two types of Context used.

Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");

DataSource ds = (DataSource) envContext.lookup("jdbc/MyABCDXYZ_DS");
 
Lucas Lee
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry,my mistake.
I mean how to bind datasource in my own code,not to configure web.xml.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic