The InitialContext is configured as a web application is initially deployed, and is made available to web application components (for read-only access). All configured entries and resources are placed in thejava:comp/env portion of the JNDI namespace, so a typical access to a resource – in this case, to a JDBCDataSource – would look something like this:
// Obtain our environment naming context
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup(“java:comp/env”);
// Look up our data source
DataSource ds = (DataSource)
envCtx.lookup(“jdbc/EmployeeDB”);
// Allocate and use a connection from the pool
Connection conn = ds.getConnection();
… use this connection to access the database …
conn.close();