DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

[Java] Read DataSource From Connection Pool (Tomcat And WAS4)

  • submit to reddit
Context initContext;
initContext = new InitialContext();
DataSource ds = null;

if ("TOMCAT".equals(appServer)) {

      //Apache Tomcat Server
      ds = (DataSource)initContext.lookup("java:comp/env/jdbc/yourJNDI");

} else if  ("WAS4".equals(appServer)) {

      //IBM WebSphere 4.x
      ds = (DataSource)initContext.lookup("jdbc/yourJNDI");