// 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();
See the following Specifications for more information about programming APIs for JNDI, and for the features supported by Java2 Enterprise Edition (J2EE) servers, which Tomcat emulates for the services that it provides:
<resource-ref> <description> Resource reference to a factory for java.sql.Connection instances that may be used for talking to a particular database that is configured in the server.xml file. </description> <res-ref-name> jdbc/EmployeeDB </res-ref-name> <res-type> javax.sql.DataSource </res-type> <res-auth> Container </res-auth> </resource-ref>