File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes looking up JNDI resource from a POJO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "looking up JNDI resource from a POJO " Watch "looking up JNDI resource from a POJO " New topic

looking up JNDI resource from a POJO

anas alsarairah

Joined: Sep 27, 2007
Posts: 28

i know this should be a very stupid question . but i have been using Ejbs since long time and i have some code to support with lots of old POJOs so my question is that can i lookup a JNDI resource from a POJO using this notaions cause i am geting a naming exception or i need a web componenet to do that and there is no way to do it from an old POJO

Connection conn = null;
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");

// Look up our data source
DataSource ds = (DataSource) envCtx.lookup("jdbc/ecs");

// Allocate and use a connection from the pool
conn = ds.getConnection();
} catch (Exception e) {
throw new ApplicationException(ECSConstants.EC_DB);

thank you in advance
wood burning stoves
subject: looking up JNDI resource from a POJO
Similar Threads
looking up JNDI resource from a POJO
Tomcat Connection Pool
DSN name not found error with TOMCAT5.5.7
J2EE Database Access ..
BMP, Jboss, and mysql configuring