Here you can find the source of getDataSource(String jndi)
static private DataSource getDataSource(String jndi)
//package com.java2s; //License from project: Open Source License import javax.sql.DataSource; public class Main { static private DataSource getDataSource(String jndi) { javax.naming.Context initContext; try {// w ww . j av a 2s . com initContext = new javax.naming.InitialContext(); return (DataSource) initContext.lookup("java:comp/env/" + jndi); } catch (Exception ex) { //log.info(ex.toString()); // try try { initContext = new javax.naming.InitialContext(); return (DataSource) initContext.lookup(jndi); } catch (Exception e) { System.err.println("Can't initialize resource " + jndi + "; not running in Tomcat/Jetty/Glassfish " + "or other app container?"); e.printStackTrace(); } } return null; } }