import java.sql.Connection;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.Datasource;


// These two calls are not normally needed. They are handled
// for you by the servlet womb.
System.setProperty(Context.PROVIDER_URL, "file:///tmp");

// accessing a database in TomCat using a Datasource.

// Obtain environment naming context
Context initalContext = new InitialContext();
Context envContext = (Context) initialContext.lookup("java:comp/env");

// Look up the data source, which knows the user/password/url/jdbc drivers etc.
DataSource ds = (DataSource)envContext.lookup( "jdbc/Mammals" );

// Allocate and use a connection from the pool
Connection conn = ds.getConnection();

// Get a statement from the connection
stmt = conn.createStatement();


// close connection