• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

looking up JNDI resource from a POJO

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello

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");
System.out.println(envCtx.getNameInNamespace());

// 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) {
e.printStackTrace();
throw new ApplicationException(ECSConstants.EC_DB);
}

thank you in advance
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic