Initial commit for Git.
This commit is contained in:
parent
98b1521e20
commit
9595f70fd7
27 changed files with 1790 additions and 1780 deletions
|
@ -1,52 +1,52 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!DOCTYPE web-app PUBLIC
|
||||
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
||||
"http://java.sun.com/dtd/web-app_2_3.dtd">
|
||||
<web-app>
|
||||
<description>SimplePool Examples</description>
|
||||
|
||||
<!--
|
||||
<servlet>
|
||||
<servlet-name>SimplePoolServlet</servlet-name>
|
||||
<servlet-class>net.java.dev.simplepool.SimplePoolServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>varName</param-name>
|
||||
<param-value>ServletPoolDS</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>driver</param-name>
|
||||
<param-value>com.mysql.jdbc.Driver</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>user</param-name>
|
||||
<param-value>dbuser</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>password</param-name>
|
||||
<param-value>dbpassword</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>jdbcUrl</param-name>
|
||||
<param-value>jdbc:mysql://localhost:3306/dbname</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>minConns</param-name>
|
||||
<param-value>8</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>maxConns</param-name>
|
||||
<param-value>30</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>maxConnTime</param-name>
|
||||
<param-value>1</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>maxCheckoutSeconds</param-name>
|
||||
<param-value>60</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
-->
|
||||
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!DOCTYPE web-app PUBLIC
|
||||
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
||||
"http://java.sun.com/dtd/web-app_2_3.dtd">
|
||||
<web-app>
|
||||
<description>SimplePool Examples</description>
|
||||
|
||||
<!--
|
||||
<servlet>
|
||||
<servlet-name>SimplePoolServlet</servlet-name>
|
||||
<servlet-class>net.java.dev.simplepool.SimplePoolServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>varName</param-name>
|
||||
<param-value>ServletPoolDS</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>driver</param-name>
|
||||
<param-value>com.mysql.jdbc.Driver</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>user</param-name>
|
||||
<param-value>dbuser</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>password</param-name>
|
||||
<param-value>dbpassword</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>jdbcUrl</param-name>
|
||||
<param-value>jdbc:mysql://localhost:3306/dbname</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>minConns</param-name>
|
||||
<param-value>8</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>maxConns</param-name>
|
||||
<param-value>30</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>maxConnTime</param-name>
|
||||
<param-value>1</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>maxCheckoutSeconds</param-name>
|
||||
<param-value>60</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
-->
|
||||
|
||||
</web-app>
|
|
@ -1,62 +1,62 @@
|
|||
<Server port="8005" shutdown="SHUTDOWN">
|
||||
<Service name="Catalina">
|
||||
<Connector port="80" />
|
||||
|
||||
<Engine name="Catalina" defaultHost="localhost">
|
||||
<Logger className="org.apache.catalina.logger.FileLogger" />
|
||||
|
||||
<Host name="localhost" appBase="webapps">
|
||||
|
||||
<!-- Define our application context -->
|
||||
<Context path="/@EX.NAME@" docBase="@EX.NAME@"
|
||||
debug="5" reloadable="true" crossContext="true">
|
||||
|
||||
<!-- Define our JDNI DataSource -->
|
||||
<Resource name="jdbc/JNDIPoolDS" type="javax.sql.DataSource" auth="Container"/>
|
||||
|
||||
<!-- Configure our JNDI DataSource -->
|
||||
<ResourceParams name="jdbc/JNDIPoolDS">
|
||||
<parameter>
|
||||
<name>factory</name>
|
||||
<value>net.java.dev.simplepool.SimplePoolDataSourceFactory</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>driver</name>
|
||||
<value>com.mysql.jdbc.Driver</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>user</name>
|
||||
<value>dbuser</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>password</name>
|
||||
<value>dbpassword</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>jdbcUrl</name>
|
||||
<value>jdbc:mysql://localhost:3306/dbname</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>minConns</name>
|
||||
<value>8</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>maxConns</name>
|
||||
<value>30</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>maxConnTime</name>
|
||||
<value>1</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>maxCheckoutSeconds</name>
|
||||
<value>60</value>
|
||||
</parameter>
|
||||
</ResourceParams>
|
||||
|
||||
</Context>
|
||||
|
||||
</Host>
|
||||
</Engine>
|
||||
</Service>
|
||||
<Server port="8005" shutdown="SHUTDOWN">
|
||||
<Service name="Catalina">
|
||||
<Connector port="80" />
|
||||
|
||||
<Engine name="Catalina" defaultHost="localhost">
|
||||
<Logger className="org.apache.catalina.logger.FileLogger" />
|
||||
|
||||
<Host name="localhost" appBase="webapps">
|
||||
|
||||
<!-- Define our application context -->
|
||||
<Context path="/@EX.NAME@" docBase="@EX.NAME@"
|
||||
debug="5" reloadable="true" crossContext="true">
|
||||
|
||||
<!-- Define our JDNI DataSource -->
|
||||
<Resource name="jdbc/JNDIPoolDS" type="javax.sql.DataSource" auth="Container"/>
|
||||
|
||||
<!-- Configure our JNDI DataSource -->
|
||||
<ResourceParams name="jdbc/JNDIPoolDS">
|
||||
<parameter>
|
||||
<name>factory</name>
|
||||
<value>net.java.dev.simplepool.SimplePoolDataSourceFactory</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>driver</name>
|
||||
<value>com.mysql.jdbc.Driver</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>user</name>
|
||||
<value>dbuser</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>password</name>
|
||||
<value>dbpassword</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>jdbcUrl</name>
|
||||
<value>jdbc:mysql://localhost:3306/dbname</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>minConns</name>
|
||||
<value>8</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>maxConns</name>
|
||||
<value>30</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>maxConnTime</name>
|
||||
<value>1</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>maxCheckoutSeconds</name>
|
||||
<value>60</value>
|
||||
</parameter>
|
||||
</ResourceParams>
|
||||
|
||||
</Context>
|
||||
|
||||
</Host>
|
||||
</Engine>
|
||||
</Service>
|
||||
</Server>
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id$
|
||||
/* $Id: inst.css,v 1.1 2004/03/20 13:36:08 erik Exp $
|
||||
|
||||
This file contains rules that extend or override the more basic formatting defined in tigris.css. Edit it to customize the look of applications using tigris.css (instances). You are responsible for maintaining your own set of (optional) deltas from tigris.css defaults; this file is intended as an example.
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id$
|
||||
/* $Id: tigris.css,v 1.1 2004/03/20 13:36:08 erik Exp $
|
||||
|
||||
This file defines basic default formatting for HTML conforming to Tigris application style. To extend or override these rules for your instance, edit inst.css instead of this file. */
|
||||
|
||||
|
|
|
@ -1,54 +1,54 @@
|
|||
<!DOCTYPE html PUBLIC "-//Tigris//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://style.tigris.org/tigris_transitional.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<style type="text/css">
|
||||
/* <![CDATA[ */
|
||||
@import "includes/tigris.css";
|
||||
@import "includes/inst.css";
|
||||
/* ]]> */
|
||||
</style>
|
||||
<title>simplepool: Examples</title>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
</head>
|
||||
<body marginwidth="0" marginheight="0" class="composite">
|
||||
<table border="0" cellspacing="0" cellpadding="4" width="100%" id="main">
|
||||
<tr valign="top">
|
||||
<td>
|
||||
<div id="bodycol">
|
||||
<div id="apphead">
|
||||
<h2><small>simplepool</small><br />
|
||||
Examples</h2>
|
||||
</div>
|
||||
<p class="tasknav"><a href="https://simplepool.dev.java.net/">Project Home</a></p>
|
||||
<div id="examples" class="app">
|
||||
<div class="axial">
|
||||
<table border="0" cellspacing="2" cellpadding="3">
|
||||
<tr>
|
||||
<th>Summary</th>
|
||||
<td>A simple database connection pool for webapps using JSTL.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Example 1</th>
|
||||
<td><a href="jndi/index.jsp">JNDI DataSource Examples</a> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Example 2</th>
|
||||
<td><a href="servlet/index.jsp">Servlet DataSource Examples</a> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="h3" id="longdescription">
|
||||
<h3>Description</h3>
|
||||
<p>SimplePool is a simple database connection pool implementation for web applications, specifically those using <a href="http://java.sun.com/products/jsp/jstl/">JSTL</a>.</p>
|
||||
<p>The connection pool can be created, accessed and managed via <a href="jndi">JNDI</a> or a provided <a href="servlet/">Servlet</a>.</p>
|
||||
<p>The examples above have been tailored for use with <a href="http://jakarta.apache.org/tomcat/">Tomcat</a> and <a href="http://www.mysql.com/">MySQL</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
<!DOCTYPE html PUBLIC "-//Tigris//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://style.tigris.org/tigris_transitional.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<style type="text/css">
|
||||
/* <![CDATA[ */
|
||||
@import "includes/tigris.css";
|
||||
@import "includes/inst.css";
|
||||
/* ]]> */
|
||||
</style>
|
||||
<title>simplepool: Examples</title>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
</head>
|
||||
<body marginwidth="0" marginheight="0" class="composite">
|
||||
<table border="0" cellspacing="0" cellpadding="4" width="100%" id="main">
|
||||
<tr valign="top">
|
||||
<td>
|
||||
<div id="bodycol">
|
||||
<div id="apphead">
|
||||
<h2><small>simplepool</small><br />
|
||||
Examples</h2>
|
||||
</div>
|
||||
<p class="tasknav"><a href="https://simplepool.dev.java.net/">Project Home</a></p>
|
||||
<div id="examples" class="app">
|
||||
<div class="axial">
|
||||
<table border="0" cellspacing="2" cellpadding="3">
|
||||
<tr>
|
||||
<th>Summary</th>
|
||||
<td>A simple database connection pool for webapps using JSTL.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Example 1</th>
|
||||
<td><a href="jndi/index.jsp">JNDI DataSource Examples</a> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Example 2</th>
|
||||
<td><a href="servlet/index.jsp">Servlet DataSource Examples</a> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="h3" id="longdescription">
|
||||
<h3>Description</h3>
|
||||
<p>SimplePool is a simple database connection pool implementation for web applications, specifically those using <a href="http://java.sun.com/products/jsp/jstl/">JSTL</a>.</p>
|
||||
<p>The connection pool can be created, accessed and managed via <a href="jndi">JNDI</a> or a provided <a href="servlet/">Servlet</a>.</p>
|
||||
<p>The examples above have been tailored for use with <a href="http://jakarta.apache.org/tomcat/">Tomcat</a> and <a href="http://www.mysql.com/">MySQL</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,84 +1,84 @@
|
|||
<!DOCTYPE html PUBLIC "-//Tigris//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://style.tigris.org/tigris_transitional.dtd">
|
||||
<%@page import="javax.naming.*" %>
|
||||
<html>
|
||||
<head>
|
||||
<style type="text/css">
|
||||
/* <![CDATA[ */
|
||||
@import "../includes/tigris.css";
|
||||
@import "../includes/inst.css";
|
||||
/* ]]> */
|
||||
</style>
|
||||
<title>simplepool: JNDI DataSource Examples</title>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
<script language="javascript" type="text/javascript">
|
||||
<%
|
||||
boolean enabled = false;
|
||||
|
||||
try {
|
||||
enabled = (new InitialContext().lookup("java:comp/env/jdbc/JNDIPoolDS") != null);
|
||||
} catch (Exception ignore) { }
|
||||
%>
|
||||
function RTFM()
|
||||
{
|
||||
alert("Please read the instructions to enable this example.");
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body marginwidth="0" marginheight="0" class="composite">
|
||||
<table border="0" cellspacing="0" cellpadding="4" width="100%" id="main">
|
||||
<tr valign="top">
|
||||
<td>
|
||||
<div id="bodycol">
|
||||
<div id="apphead">
|
||||
<h2><small>simplepool</small><br />
|
||||
JNDI DataSource Examples</h2>
|
||||
</div>
|
||||
<p class="tasknav"><a href="../index.html">Examples Home</a></p>
|
||||
<p><strong>Please read the instructions before trying to run the examples.</strong></p>
|
||||
<div id="examples" class="app">
|
||||
<div class="axial">
|
||||
<table border="0" cellspacing="2" cellpadding="3">
|
||||
<tr>
|
||||
<th>Summary</th>
|
||||
<td>A simple database connection pool example using JDNI.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Example 1</th>
|
||||
<td><a href="<% if (enabled) { %>scriptlet.jsp<% } else { %>javascript:RTFM()<% } %>">Scriptlet Example</a> [<a href="../source.jsp?file=jndi/scriptlet.jsp">source</a>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Example 2</th>
|
||||
<td><a href="<% if (enabled) { %>jstl.jsp<% } else { %>javascript:RTFM()<% } %>">JSTL Example</a> [<a href="../source.jsp?file=jndi/jstl.jsp">source</a>]</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="h3" id="instructions">
|
||||
<h3>Instructions</h3>
|
||||
<p>JNDI is used to create, access and manage the connection pool.</p>
|
||||
<p class="alert">First, make sure that your JDBC driver is available, by placing its components in this webapp's WEB-INF/lib/ directory.</p>
|
||||
<p class="alert">The JNDI DataSource is defined as naming resource in the current webapp context, as shown in this minimal <a href="../source.jsp?file=conf/server.xml">server configuration file</a>. </p>
|
||||
<p>The JNDI DataSource is configured using the following parameters:</p>
|
||||
<ul>
|
||||
<li>The <span class="info">varName</span> parameter is used to specify the name of the variable which will hold a reference to the DataSource object created by the Servlet.</li>
|
||||
<li>The <span class="info">driver</span> parameter is used to specify the name of the JDBC driver class to be registered. For <code>example: com.mysql.jdbc.Driver</code>.</li>
|
||||
<li>The <span class="info">user</span> parameter is used to specify the database username, if any.</li>
|
||||
<li>The <span class="info">password</span> parameter is used to specify the database password, if any.</li>
|
||||
<li>The <span class="info">jdbcUrl</span> parameter is used to specify the JDBC URL associated with the database. For example: <code>jdbc:mysql://localhost:3306/dbname</code>.</li>
|
||||
<li>The <span class="info">minConns</span> parameter is used to specify the minimum number of connections to start the pool with.</li>
|
||||
<li>The <span class="info">maxConns</span> parameter is used to specify the maximum number of connections to be dynamically created in the pool.</li>
|
||||
<li>The <span class="info">maxConnTime</span> parameter is used to specify the time (in days) between connection resets. The pool manager will perform a basic cleanup at the specified interval.</li>
|
||||
<li>The <span class="info">maxCheckoutSeconds</span> parameter is used to specify the maximum time a connection can be checked out before being recycled. A zero value turns this option off.</li>
|
||||
</ul>
|
||||
<p>Please note that <em>all parameters are required</em>.</p>
|
||||
<p class="alert">Please take a minute to incorporate the <a href="../source.jsp?file=conf/server.xml">JDNI DataSource example</a> in your <code>$CATALINE_HOME/conf/server.xml</code>. Once done, please restart Tomcat. The examples will be functional upon restart.</p>
|
||||
<p>Please look at the [source] of the provided examples to understand how to access the connection pool from a scriptlet or using the JSTL SQL tags. The examples demonstrates how to list all of the tables contained in the specified database.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
<!DOCTYPE html PUBLIC "-//Tigris//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://style.tigris.org/tigris_transitional.dtd">
|
||||
<%@page import="javax.naming.*" %>
|
||||
<html>
|
||||
<head>
|
||||
<style type="text/css">
|
||||
/* <![CDATA[ */
|
||||
@import "../includes/tigris.css";
|
||||
@import "../includes/inst.css";
|
||||
/* ]]> */
|
||||
</style>
|
||||
<title>simplepool: JNDI DataSource Examples</title>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
<script language="javascript" type="text/javascript">
|
||||
<%
|
||||
boolean enabled = false;
|
||||
|
||||
try {
|
||||
enabled = (new InitialContext().lookup("java:comp/env/jdbc/JNDIPoolDS") != null);
|
||||
} catch (Exception ignore) { }
|
||||
%>
|
||||
function RTFM()
|
||||
{
|
||||
alert("Please read the instructions to enable this example.");
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body marginwidth="0" marginheight="0" class="composite">
|
||||
<table border="0" cellspacing="0" cellpadding="4" width="100%" id="main">
|
||||
<tr valign="top">
|
||||
<td>
|
||||
<div id="bodycol">
|
||||
<div id="apphead">
|
||||
<h2><small>simplepool</small><br />
|
||||
JNDI DataSource Examples</h2>
|
||||
</div>
|
||||
<p class="tasknav"><a href="../index.html">Examples Home</a></p>
|
||||
<p><strong>Please read the instructions before trying to run the examples.</strong></p>
|
||||
<div id="examples" class="app">
|
||||
<div class="axial">
|
||||
<table border="0" cellspacing="2" cellpadding="3">
|
||||
<tr>
|
||||
<th>Summary</th>
|
||||
<td>A simple database connection pool example using JDNI.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Example 1</th>
|
||||
<td><a href="<% if (enabled) { %>scriptlet.jsp<% } else { %>javascript:RTFM()<% } %>">Scriptlet Example</a> [<a href="../source.jsp?file=jndi/scriptlet.jsp">source</a>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Example 2</th>
|
||||
<td><a href="<% if (enabled) { %>jstl.jsp<% } else { %>javascript:RTFM()<% } %>">JSTL Example</a> [<a href="../source.jsp?file=jndi/jstl.jsp">source</a>]</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="h3" id="instructions">
|
||||
<h3>Instructions</h3>
|
||||
<p>JNDI is used to create, access and manage the connection pool.</p>
|
||||
<p class="alert">First, make sure that your JDBC driver is available, by placing its components in this webapp's WEB-INF/lib/ directory.</p>
|
||||
<p class="alert">The JNDI DataSource is defined as naming resource in the current webapp context, as shown in this minimal <a href="../source.jsp?file=conf/server.xml">server configuration file</a>. </p>
|
||||
<p>The JNDI DataSource is configured using the following parameters:</p>
|
||||
<ul>
|
||||
<li>The <span class="info">varName</span> parameter is used to specify the name of the variable which will hold a reference to the DataSource object created by the Servlet.</li>
|
||||
<li>The <span class="info">driver</span> parameter is used to specify the name of the JDBC driver class to be registered. For <code>example: com.mysql.jdbc.Driver</code>.</li>
|
||||
<li>The <span class="info">user</span> parameter is used to specify the database username, if any.</li>
|
||||
<li>The <span class="info">password</span> parameter is used to specify the database password, if any.</li>
|
||||
<li>The <span class="info">jdbcUrl</span> parameter is used to specify the JDBC URL associated with the database. For example: <code>jdbc:mysql://localhost:3306/dbname</code>.</li>
|
||||
<li>The <span class="info">minConns</span> parameter is used to specify the minimum number of connections to start the pool with.</li>
|
||||
<li>The <span class="info">maxConns</span> parameter is used to specify the maximum number of connections to be dynamically created in the pool.</li>
|
||||
<li>The <span class="info">maxConnTime</span> parameter is used to specify the time (in days) between connection resets. The pool manager will perform a basic cleanup at the specified interval.</li>
|
||||
<li>The <span class="info">maxCheckoutSeconds</span> parameter is used to specify the maximum time a connection can be checked out before being recycled. A zero value turns this option off.</li>
|
||||
</ul>
|
||||
<p>Please note that <em>all parameters are required</em>.</p>
|
||||
<p class="alert">Please take a minute to incorporate the <a href="../source.jsp?file=conf/server.xml">JDNI DataSource example</a> in your <code>$CATALINE_HOME/conf/server.xml</code>. Once done, please restart Tomcat. The examples will be functional upon restart.</p>
|
||||
<p>Please look at the [source] of the provided examples to understand how to access the connection pool from a scriptlet or using the JSTL SQL tags. The examples demonstrates how to list all of the tables contained in the specified database.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
|
||||
<html>
|
||||
<head>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>SimplePool JNDI/JSTL Example</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<%-- Execute the query using our JNDI DataSource --%>
|
||||
<sql:query var="rs" dataSource="jdbc/JNDIPoolDS">
|
||||
<body>
|
||||
|
||||
<%-- Execute the query using our JNDI DataSource --%>
|
||||
<sql:query var="rs" dataSource="jdbc/JNDIPoolDS">
|
||||
SHOW TABLES
|
||||
</sql:query>
|
||||
|
||||
</sql:query>
|
||||
|
||||
<h3>Tables</h3>
|
||||
<ul>
|
||||
|
||||
<%--
|
||||
Loop through the result set and
|
||||
display the current column value
|
||||
--%>
|
||||
<ul>
|
||||
|
||||
<%--
|
||||
Loop through the result set and
|
||||
display the current column value
|
||||
--%>
|
||||
<c:forEach var="row" items="${rs.rowsByIndex}">
|
||||
<li><c:out value="${row[0]}"/></li>
|
||||
</c:forEach>
|
||||
|
||||
<ul>
|
||||
</c:forEach>
|
||||
|
||||
<ul>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,45 +1,45 @@
|
|||
<%@page import="javax.naming.*, javax.sql.*, java.sql.*;" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>SimplePool JNDI Example</title>
|
||||
<%@page import="javax.naming.*, javax.sql.*, java.sql.*;" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>SimplePool JNDI Example</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<%
|
||||
// Get a new initial JNDI context
|
||||
Context ctx = new InitialContext();
|
||||
|
||||
<body>
|
||||
|
||||
<%
|
||||
// Get a new initial JNDI context
|
||||
Context ctx = new InitialContext();
|
||||
|
||||
// Get a reference to our JNDI DataSource
|
||||
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/JNDIPoolDS");
|
||||
|
||||
// Get a connection from the pool
|
||||
Connection conn = ds.getConnection();
|
||||
|
||||
// Create a new statement
|
||||
Statement stmt = conn.createStatement();
|
||||
|
||||
// Execute the query
|
||||
ResultSet rst = stmt.executeQuery("SHOW TABLES");
|
||||
%>
|
||||
|
||||
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/JNDIPoolDS");
|
||||
|
||||
// Get a connection from the pool
|
||||
Connection conn = ds.getConnection();
|
||||
|
||||
// Create a new statement
|
||||
Statement stmt = conn.createStatement();
|
||||
|
||||
// Execute the query
|
||||
ResultSet rst = stmt.executeQuery("SHOW TABLES");
|
||||
%>
|
||||
|
||||
<h3>Tables</h3>
|
||||
<ul>
|
||||
<%
|
||||
// Loop through the result set and
|
||||
// display the current column value
|
||||
while (rst.next()) {
|
||||
%>
|
||||
<li><%= rst.getString(1) %></li>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
<ul>
|
||||
|
||||
<%
|
||||
// Close the result set, statement and connection
|
||||
rst.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
%>
|
||||
<ul>
|
||||
<%
|
||||
// Loop through the result set and
|
||||
// display the current column value
|
||||
while (rst.next()) {
|
||||
%>
|
||||
<li><%= rst.getString(1) %></li>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
<ul>
|
||||
|
||||
<%
|
||||
// Close the result set, statement and connection
|
||||
rst.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
%>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,56 +1,56 @@
|
|||
/* ========================================================================= *
|
||||
* *
|
||||
* The Apache Software License, Version 1.1 *
|
||||
* *
|
||||
* Copyright (c) 1999, 2000 The Apache Software Foundation. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* ========================================================================= *
|
||||
* *
|
||||
* Redistribution and use in source and binary forms, with or without modi- *
|
||||
* fication, are permitted provided that the following conditions are met: *
|
||||
* *
|
||||
* 1. Redistributions of source code must retain the above copyright notice, *
|
||||
* this list of conditions and the following disclaimer. *
|
||||
* *
|
||||
* 2. Redistributions in binary form must reproduce the above copyright *
|
||||
* notice, this list of conditions and the following disclaimer in the *
|
||||
* documentation and/or other materials provided with the distribution. *
|
||||
* *
|
||||
* 3. The end-user documentation included with the redistribution, if any, *
|
||||
* must include the following acknowlegement: *
|
||||
* *
|
||||
* "This product includes software developed by the Apache Software *
|
||||
* Foundation <http://www.apache.org/>." *
|
||||
* *
|
||||
* Alternately, this acknowlegement may appear in the software itself, if *
|
||||
* and wherever such third-party acknowlegements normally appear. *
|
||||
* *
|
||||
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software *
|
||||
* Foundation" must not be used to endorse or promote products derived *
|
||||
* from this software without prior written permission. For written *
|
||||
* permission, please contact <apache@apache.org>. *
|
||||
* *
|
||||
* 5. Products derived from this software may not be called "Apache" nor may *
|
||||
* "Apache" appear in their names without prior written permission of the *
|
||||
* Apache Software Foundation. *
|
||||
* *
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY *
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
|
||||
* THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY *
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, *
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
|
||||
* POSSIBILITY OF SUCH DAMAGE. *
|
||||
* *
|
||||
* ========================================================================= *
|
||||
* *
|
||||
* This software consists of voluntary contributions made by many indivi- *
|
||||
* duals on behalf of the Apache Software Foundation. For more information *
|
||||
* on the Apache Software Foundation, please see <http://www.apache.org/>. *
|
||||
* *
|
||||
* ========================================================================= */
|
||||
/* ========================================================================= *
|
||||
* *
|
||||
* The Apache Software License, Version 1.1 *
|
||||
* *
|
||||
* Copyright (c) 1999, 2000 The Apache Software Foundation. *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* ========================================================================= *
|
||||
* *
|
||||
* Redistribution and use in source and binary forms, with or without modi- *
|
||||
* fication, are permitted provided that the following conditions are met: *
|
||||
* *
|
||||
* 1. Redistributions of source code must retain the above copyright notice, *
|
||||
* this list of conditions and the following disclaimer. *
|
||||
* *
|
||||
* 2. Redistributions in binary form must reproduce the above copyright *
|
||||
* notice, this list of conditions and the following disclaimer in the *
|
||||
* documentation and/or other materials provided with the distribution. *
|
||||
* *
|
||||
* 3. The end-user documentation included with the redistribution, if any, *
|
||||
* must include the following acknowlegement: *
|
||||
* *
|
||||
* "This product includes software developed by the Apache Software *
|
||||
* Foundation <http://www.apache.org/>." *
|
||||
* *
|
||||
* Alternately, this acknowlegement may appear in the software itself, if *
|
||||
* and wherever such third-party acknowlegements normally appear. *
|
||||
* *
|
||||
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software *
|
||||
* Foundation" must not be used to endorse or promote products derived *
|
||||
* from this software without prior written permission. For written *
|
||||
* permission, please contact <apache@apache.org>. *
|
||||
* *
|
||||
* 5. Products derived from this software may not be called "Apache" nor may *
|
||||
* "Apache" appear in their names without prior written permission of the *
|
||||
* Apache Software Foundation. *
|
||||
* *
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY *
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
|
||||
* THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY *
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, *
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
|
||||
* POSSIBILITY OF SUCH DAMAGE. *
|
||||
* *
|
||||
* ========================================================================= *
|
||||
* *
|
||||
* This software consists of voluntary contributions made by many indivi- *
|
||||
* duals on behalf of the Apache Software Foundation. For more information *
|
||||
* on the Apache Software Foundation, please see <http://www.apache.org/>. *
|
||||
* *
|
||||
* ========================================================================= */
|
||||
|
|
|
@ -1,38 +1,38 @@
|
|||
/*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the authors nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
/*
|
||||
* $Source: /home/cvsroot/manywhere/simplepool/simplepool-examples/licenses/SimplePool\040License.txt,v $
|
||||
* $Revision: 1.1 $
|
||||
* $Date: 2004/03/20 13:36:08 $
|
||||
*
|
||||
* Copyright (c) 2004, Russell Beattie (http://www.russellbeattie.com/)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the authors nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
|
@ -1,77 +1,77 @@
|
|||
<!DOCTYPE html PUBLIC "-//Tigris//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://style.tigris.org/tigris_transitional.dtd">
|
||||
<%@page import="javax.naming.*" %>
|
||||
<html>
|
||||
<head>
|
||||
<style type="text/css">
|
||||
/* <![CDATA[ */
|
||||
@import "../includes/tigris.css";
|
||||
@import "../includes/inst.css";
|
||||
/* ]]> */
|
||||
</style>
|
||||
<title>simplepool: Servlet DataSource Examples</title>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
<script language="javascript" type="text/javascript">
|
||||
<% boolean enabled = (pageContext.findAttribute("ServletPoolDS") != null); %>
|
||||
function RTFM()
|
||||
{
|
||||
alert("Please read the instructions to enable this example.");
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body marginwidth="0" marginheight="0" class="composite">
|
||||
<table border="0" cellspacing="0" cellpadding="4" width="100%" id="main">
|
||||
<tr valign="top">
|
||||
<td>
|
||||
<div id="bodycol">
|
||||
<div id="apphead">
|
||||
<h2><small>simplepool</small><br />
|
||||
Servlet DataSource Examples</h2>
|
||||
</div>
|
||||
<p class="tasknav"><a href="../index.html">Examples Home</a></p>
|
||||
<p><strong>Please read the instructions before trying to run the examples.</strong></p>
|
||||
<div id="examples" class="app">
|
||||
<div class="axial">
|
||||
<table border="0" cellspacing="2" cellpadding="3">
|
||||
<tr>
|
||||
<th>Summary</th>
|
||||
<td>A simple database connection pool example using the SimplePool Servlet.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Example 1</th>
|
||||
<td><a href="<% if (enabled) { %>scriptlet.jsp<% } else { %>javascript:RTFM()<% } %>">Scriptlet Example</a> [<a href="../source.jsp?file=servlet/scriptlet.jsp">source</a>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Example 2</th>
|
||||
<td><a href="<% if (enabled) { %>jstl.jsp<% } else { %>javascript:RTFM()<% } %>">JSTL Example</a> [<a href="../source.jsp?file=servlet/jstl.jsp">source</a>]</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="h3" id="instructions">
|
||||
<h3>Instructions</h3>
|
||||
<p>The SimplePoolServlet is used to create, access and manage the connection pool.</p>
|
||||
<p class="alert">First, make sure that your JDBC driver is available, by placing its components in this webapp's WEB-INF/lib/ directory.</p>
|
||||
<p>The SimplePoolServlet is configured using a set of required initialization parameters, as show in this webapp's <code><a href="../source.jsp?file=WEB-INF/web.xml">WEB-INF/web.xml</a></code> under the <code><servlet/></code> section:</p>
|
||||
<ul>
|
||||
<li>The <code class="info">varName</code> initialization parameter is used to specify the name of the variable which will hold a reference to the DataSource object created by the Servlet.</li>
|
||||
<li>The <code class="info">driver</code> initialization parameter is used to specify the name of the JDBC driver class to be registered. For <code>example: com.mysql.jdbc.Driver</code>.</li>
|
||||
<li>The <span class="info">user</span> initialization parameter is used to specify the database username, if any.</li>
|
||||
<li>The <code class="info">password</code> initialization parameter is used to specify the database password, if any.</li>
|
||||
<li>The <code class="info">jdbcUrl</code> initialization parameter is used to specify the JDBC URL associated with the database. For example: <code>jdbc:mysql://localhost:3306/dbname</code>.</li>
|
||||
<li>The <code class="info">minConns</code> initialization parameter is used to specify the minimum number of connections to start the pool with.</li>
|
||||
<li>The <code class="info">maxConns</code> initialization parameter is used to specify the maximum number of connections to be dynamically created in the pool.</li>
|
||||
<li>The <code class="info">maxConnTime</code> initialization parameter is used to specify the time (in days) between connection resets. The pool manager will perform a basic cleanup at the specified interval.</li>
|
||||
<li>The <code class="info">maxCheckoutSeconds</code> initialization parameter is used to specify the maximum time a connection can be checked out before being recycled. A zero value turns this option off.</li>
|
||||
</ul>
|
||||
<p>Please note that <em>all parameters are required</em>.</p>
|
||||
<p class="alert">Please take a minute to uncomment the <code><servlet/></code> declaration and configure the Servlet's initialization parameters in this webapp's <code><a href="../source.jsp?file=WEB-INF/web.xml">WEB-INF/web.xml</a></code>. Once done, please restart the webapp and/or Tomcat. The examples will be functional upon restart.</p>
|
||||
<p>Please look at the [source] of the provided examples to understand how to access the connection pool from a scriptlet or using the JSTL SQL tags. The examples demonstrates how to list all of the tables contained in the specified database.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
<!DOCTYPE html PUBLIC "-//Tigris//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://style.tigris.org/tigris_transitional.dtd">
|
||||
<%@page import="javax.naming.*" %>
|
||||
<html>
|
||||
<head>
|
||||
<style type="text/css">
|
||||
/* <![CDATA[ */
|
||||
@import "../includes/tigris.css";
|
||||
@import "../includes/inst.css";
|
||||
/* ]]> */
|
||||
</style>
|
||||
<title>simplepool: Servlet DataSource Examples</title>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
<script language="javascript" type="text/javascript">
|
||||
<% boolean enabled = (pageContext.findAttribute("ServletPoolDS") != null); %>
|
||||
function RTFM()
|
||||
{
|
||||
alert("Please read the instructions to enable this example.");
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body marginwidth="0" marginheight="0" class="composite">
|
||||
<table border="0" cellspacing="0" cellpadding="4" width="100%" id="main">
|
||||
<tr valign="top">
|
||||
<td>
|
||||
<div id="bodycol">
|
||||
<div id="apphead">
|
||||
<h2><small>simplepool</small><br />
|
||||
Servlet DataSource Examples</h2>
|
||||
</div>
|
||||
<p class="tasknav"><a href="../index.html">Examples Home</a></p>
|
||||
<p><strong>Please read the instructions before trying to run the examples.</strong></p>
|
||||
<div id="examples" class="app">
|
||||
<div class="axial">
|
||||
<table border="0" cellspacing="2" cellpadding="3">
|
||||
<tr>
|
||||
<th>Summary</th>
|
||||
<td>A simple database connection pool example using the SimplePool Servlet.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Example 1</th>
|
||||
<td><a href="<% if (enabled) { %>scriptlet.jsp<% } else { %>javascript:RTFM()<% } %>">Scriptlet Example</a> [<a href="../source.jsp?file=servlet/scriptlet.jsp">source</a>]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Example 2</th>
|
||||
<td><a href="<% if (enabled) { %>jstl.jsp<% } else { %>javascript:RTFM()<% } %>">JSTL Example</a> [<a href="../source.jsp?file=servlet/jstl.jsp">source</a>]</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="h3" id="instructions">
|
||||
<h3>Instructions</h3>
|
||||
<p>The SimplePoolServlet is used to create, access and manage the connection pool.</p>
|
||||
<p class="alert">First, make sure that your JDBC driver is available, by placing its components in this webapp's WEB-INF/lib/ directory.</p>
|
||||
<p>The SimplePoolServlet is configured using a set of required initialization parameters, as show in this webapp's <code><a href="../source.jsp?file=WEB-INF/web.xml">WEB-INF/web.xml</a></code> under the <code><servlet/></code> section:</p>
|
||||
<ul>
|
||||
<li>The <code class="info">varName</code> initialization parameter is used to specify the name of the variable which will hold a reference to the DataSource object created by the Servlet.</li>
|
||||
<li>The <code class="info">driver</code> initialization parameter is used to specify the name of the JDBC driver class to be registered. For <code>example: com.mysql.jdbc.Driver</code>.</li>
|
||||
<li>The <span class="info">user</span> initialization parameter is used to specify the database username, if any.</li>
|
||||
<li>The <code class="info">password</code> initialization parameter is used to specify the database password, if any.</li>
|
||||
<li>The <code class="info">jdbcUrl</code> initialization parameter is used to specify the JDBC URL associated with the database. For example: <code>jdbc:mysql://localhost:3306/dbname</code>.</li>
|
||||
<li>The <code class="info">minConns</code> initialization parameter is used to specify the minimum number of connections to start the pool with.</li>
|
||||
<li>The <code class="info">maxConns</code> initialization parameter is used to specify the maximum number of connections to be dynamically created in the pool.</li>
|
||||
<li>The <code class="info">maxConnTime</code> initialization parameter is used to specify the time (in days) between connection resets. The pool manager will perform a basic cleanup at the specified interval.</li>
|
||||
<li>The <code class="info">maxCheckoutSeconds</code> initialization parameter is used to specify the maximum time a connection can be checked out before being recycled. A zero value turns this option off.</li>
|
||||
</ul>
|
||||
<p>Please note that <em>all parameters are required</em>.</p>
|
||||
<p class="alert">Please take a minute to uncomment the <code><servlet/></code> declaration and configure the Servlet's initialization parameters in this webapp's <code><a href="../source.jsp?file=WEB-INF/web.xml">WEB-INF/web.xml</a></code>. Once done, please restart the webapp and/or Tomcat. The examples will be functional upon restart.</p>
|
||||
<p>Please look at the [source] of the provided examples to understand how to access the connection pool from a scriptlet or using the JSTL SQL tags. The examples demonstrates how to list all of the tables contained in the specified database.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>SimplePool Servlet/JSTL Example</title>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>SimplePool Servlet/JSTL Example</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<%-- Execute the query using our DataSource --%>
|
||||
<sql:query var="rs" dataSource="${ServletPoolDS}">
|
||||
<body>
|
||||
|
||||
<%-- Execute the query using our DataSource --%>
|
||||
<sql:query var="rs" dataSource="${ServletPoolDS}">
|
||||
SHOW TABLES
|
||||
</sql:query>
|
||||
|
||||
</sql:query>
|
||||
|
||||
<h3>Tables</h3>
|
||||
<ul>
|
||||
|
||||
<%--
|
||||
Loop through the result set and
|
||||
display the current column value
|
||||
--%>
|
||||
<ul>
|
||||
|
||||
<%--
|
||||
Loop through the result set and
|
||||
display the current column value
|
||||
--%>
|
||||
<c:forEach var="row" items="${rs.rowsByIndex}">
|
||||
<li><c:out value="${row[0]}"/></li>
|
||||
</c:forEach>
|
||||
|
||||
<ul>
|
||||
</c:forEach>
|
||||
|
||||
<ul>
|
||||
</body>
|
||||
</html>
|
|
@ -1,44 +1,44 @@
|
|||
<%@page import="javax.naming.*, javax.sql.*, java.sql.*;" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>SimplePool Servlet Example</title>
|
||||
<%@page import="javax.naming.*, javax.sql.*, java.sql.*;" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>SimplePool Servlet Example</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<%
|
||||
<body>
|
||||
|
||||
<%
|
||||
// Get a reference to our DataSource
|
||||
DataSource ds = (DataSource) pageContext.findAttribute("ServletPoolDS");
|
||||
|
||||
// Get a connection from the pool
|
||||
Connection conn = ds.getConnection();
|
||||
|
||||
// Create a new statement
|
||||
Statement stmt = conn.createStatement();
|
||||
|
||||
// Execute the query
|
||||
ResultSet rst = stmt.executeQuery("SHOW TABLES");
|
||||
%>
|
||||
|
||||
DataSource ds = (DataSource) pageContext.findAttribute("ServletPoolDS");
|
||||
|
||||
// Get a connection from the pool
|
||||
Connection conn = ds.getConnection();
|
||||
|
||||
// Create a new statement
|
||||
Statement stmt = conn.createStatement();
|
||||
|
||||
// Execute the query
|
||||
ResultSet rst = stmt.executeQuery("SHOW TABLES");
|
||||
%>
|
||||
|
||||
<h3>Tables</h3>
|
||||
<ul>
|
||||
<%
|
||||
// Loop through the result set and
|
||||
// display the current column value
|
||||
while (rst.next()) {
|
||||
%>
|
||||
<li><%= rst.getString(1) %></li>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
<ul>
|
||||
|
||||
<%
|
||||
// Close the result set, statement and connection
|
||||
// and display the current column value
|
||||
rst.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
%>
|
||||
<ul>
|
||||
<%
|
||||
// Loop through the result set and
|
||||
// display the current column value
|
||||
while (rst.next()) {
|
||||
%>
|
||||
<li><%= rst.getString(1) %></li>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
<ul>
|
||||
|
||||
<%
|
||||
// Close the result set, statement and connection
|
||||
// and display the current column value
|
||||
rst.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
%>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
<%@page import="java.io.*"%>
|
||||
<html>
|
||||
<body>
|
||||
<pre>
|
||||
<%
|
||||
<%@page import="java.io.*"%>
|
||||
<html>
|
||||
<body>
|
||||
<pre>
|
||||
<%
|
||||
String file = request.getParameter("file");
|
||||
if ((file != null) && (file.trim().length() > 0) && (file.indexOf( ".." ) == -1)) {
|
||||
InputStream is = pageContext.getServletContext().getResourceAsStream(file);
|
||||
if (is != null) {
|
||||
InputStreamReader isr = new InputStreamReader(is);
|
||||
for (int ch = isr.read(); ch != -1; ch = isr.read()) {
|
||||
if (ch == '<') {
|
||||
out.print("<");
|
||||
} else if (ch == '\t') {
|
||||
out.print(" ");
|
||||
} else {
|
||||
out.print((char) ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
%>
|
||||
</pre>
|
||||
if (is != null) {
|
||||
InputStreamReader isr = new InputStreamReader(is);
|
||||
for (int ch = isr.read(); ch != -1; ch = isr.read()) {
|
||||
if (ch == '<') {
|
||||
out.print("<");
|
||||
} else if (ch == '\t') {
|
||||
out.print(" ");
|
||||
} else {
|
||||
out.print((char) ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
%>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue