wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Can I bind datasource to java:comp/env/myName JNDI? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Can I bind datasource to java:comp/env/myName JNDI?" Watch "Can I bind datasource to java:comp/env/myName JNDI?" New topic
Author

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

Lucas Lee
Ranch Hand

Joined: Oct 02, 2006
Posts: 53
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

Joined: Sep 06, 2003
Posts: 259
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");


http://www.skillassert.com


Lucas Lee
Ranch Hand

Joined: Oct 02, 2006
Posts: 53
Sorry,my mistake.
I mean how to bind datasource in my own code,not to configure web.xml.
 
wood burning stoves
 
subject: Can I bind datasource to java:comp/env/myName JNDI?
 
Similar Threads
@Resource injection problem with JNDI
When we have JNDI address for a jdbc datasource , how we can make connection for it?
datasource for mysql
Datasource JNDI Lookup in WSAD from standalone app
doubt in enthuware com.enthuware.ets.scbcd.v5.2.12 - Objective Bean Environment