1.
META-INF/context.xml
<Context>
<Resource name="jdbc/dbname" auth="Container" type="javax.sql.DataSource"
maxTotal="100" maxIdle="30" maxWaitMillis="15000"
username="name" password="pw" driverClassName="com.ibm.db2.jcc.DB2Driver"
url="jdbc:db2://10.10.10.10:50000/dbname"/>
</Context>
2.
WEB-INF/web.xml
<web-app >
<resource-ref>
<description>dbname connect description</description>
<res-ref-name>jdbc/dbname</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
3.
JSP page
<%
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource dataSource = (DataSource)envContext.lookup("jdbc/dbname");
Connection con = dataSource.getConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM DB");
%>