Creating a JNDI DBCP Connection Pool
Copy the source code below into a file called test.jsp in your application's main folder.
Your application directory structure will look something like this:
JAKARTA-WEBAPPS
JAKARTA-WEBAPPS/JNDIApp
JAKARTA-WEBAPPS/JNDIApp/test.jsp
JAKARTA-WEBAPPS/JNDIApp/WEB-INF
JAKARTA-WEBAPPS/JNDIApp/WEB-INF/web.xml
JAKARTA-WEBAPPS/JNDIApp/WEB-INF/lib
JAKARTA-WEBAPPS/JNDIApp/WEB-INF/lib/jstl.jar (required for using JSTL only)
JAKARTA-WEBAPPS/JNDIApp/WEB-INF/lib/standard.jar (required for using JSTL only)
JAKARTA-WEBAPPS/JNDIApp/META-INF
JAKARTA-WEBAPPS/JNDIApp/META-INF/context.xml
Source Code (Copy and Paste):
<%--
/*
* @(#)test.jsp (Metawerx customer example classes)
*
* Copyright (c) 1998-2007 Metawerx. All Rights Reserved.
*
* This software is the confidential and proprietary information of Metawerx
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the
* license agreement you entered into with Metawerx.
*
* METAWERX MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
* OF THE SOFTWARE OR THE SOURCE CODE, EITHER EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
* A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. METAWERX SHALL NOT BE LIABLE
* FOR ANY DAMAGES SUFFERED BY ANY PARTY AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE AND DOCUMENTATION OR ITS DERIVATIVES
*
*
* Synopsis
* =====================================================================================
* This code demonstrates the use of a JNDI DBCP Connection Pool entry
* to run and output data from an SQL query using JSTL.
*
* Requirements
* =====================================================================================
* This code requires the jstl.jar and standard.jar files to use JSTL.
* Using JNDI, the JDBC driver must be available in Tomcat's CLASSPATH.
* Making it part of the application's CLASSPATH is not sufficient.
*
* Complete file structure for Tomcat for this sample
* =====================================================================================
JAKARTA-WEBAPPS
JAKARTA-WEBAPPS/JNDIApp
JAKARTA-WEBAPPS/JNDIApp/test.jsp
JAKARTA-WEBAPPS/JNDIApp/WEB-INF
JAKARTA-WEBAPPS/JNDIApp/WEB-INF/web.xml
JAKARTA-WEBAPPS/JNDIApp/WEB-INF/lib
JAKARTA-WEBAPPS/JNDIApp/WEB-INF/lib/jstl.jar
JAKARTA-WEBAPPS/JNDIApp/WEB-INF/lib/standard.jar
JAKARTA-WEBAPPS/JNDIApp/META-INF
JAKARTA-WEBAPPS/JNDIApp/META-INF/context.xml
*
* Complete, minimal web.xml file for this sample
* =====================================================================================
* History
* =====================================================================================
* 2006/04/19 9:22 Neale Rudd
* Added this example
*
*/
--%>
<%@ page pageEncoding="UTF-8" contentType="text/html" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
JNDI DBCP Test Page
JNDI DBCP Test Page
Executing the query ...
<%-- Note: Enter a query that is valid for your database here --%>
SELECT * FROM products
<%-- Output column names on a header row --%>
|
<%-- Output each row of data --%>
<%-- Output each column of data --%>
|