%@page import="javax.naming.*" %>
simplepool
|
Summary | A simple database connection pool example using the SimplePool Servlet. |
---|---|
Example 1 | Scriptlet Example [source] |
Example 2 | JSTL Example [source] |
The SimplePoolServlet is used to create, access and manage the connection pool.
First, make sure that your JDBC driver is available, by placing its components in this webapp's WEB-INF/lib/ directory.
The SimplePoolServlet is configured using a set of required initialization parameters, as show in this webapp's WEB-INF/web.xml
under the <servlet/>
section:
varName
initialization parameter is used to specify the name of the variable which will hold a reference to the DataSource object created by the Servlet.driver
initialization parameter is used to specify the name of the JDBC driver class to be registered. For example: com.mysql.jdbc.Driver
.password
initialization parameter is used to specify the database password, if any.jdbcUrl
initialization parameter is used to specify the JDBC URL associated with the database. For example: jdbc:mysql://localhost:3306/dbname
.minConns
initialization parameter is used to specify the minimum number of connections to start the pool with.maxConns
initialization parameter is used to specify the maximum number of connections to be dynamically created in the pool.maxConnTime
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.maxCheckoutSeconds
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.Please note that all parameters are required.
Please take a minute to uncomment the <servlet/>
declaration and configure the Servlet's initialization parameters in this webapp's WEB-INF/web.xml
. Once done, please restart the webapp and/or Tomcat. The examples will be functional upon restart.
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.