ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahh_5.4.0.1/jdbcconnpool.htm

90 lines
5.0 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="AS400JDBCConnectionPool" />
<meta name="abstract" content="" />
<meta name="description" content="" />
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="jdbcconnpool" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>AS400JDBCConnectionPool</title>
</head>
<body id="jdbcconnpool"><a name="jdbcconnpool"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">AS400JDBCConnectionPool</h1>
<div><p></p>
<div class="section"><p>The <a href="javadoc/com/ibm/as400/access/AS400JDBCConnectionPool.html#NAVBAR_TOP"> AS400JDBCConnectionPool</a> class represents a pool of <a href="javadoc/com/ibm/as400/access/AS400JDBCConnection.html#NAVBAR_TOP"> AS400JDBCConnection</a> objects that are available for use
by a Java™ program
as part of IBM<sup>®</sup> Toolbox
for Java support
for the JDBC 2.0 Optional Package API.</p>
<p>You can use an <a href="javadoc/com/ibm/as400/access/AS400JDBCConnectionPoolDataSource.html#NAVBAR_TOP"> AS400JDBCConnectionPoolDataSource</a> to specify properties
for the connections that are created in the pool, as in the following <a href="#jdbcconnpool__jdbcconex">example</a>.</p>
<p>You cannot change the
connection pool data source after you have requested a connection and the
pool is in use. To reset the connection pool data source, first call <a href="javadoc/com/ibm/as400/access/AS400JDBCConnectionPool.html#CLOSE()"> close()</a> on the pool.</p>
<p>Return connections to an
AS400JDBCConnectionPool by using <a href="javadoc/com/ibm/as400/access/AS400JDBCConnection.html#CLOSE()"> close()</a> on the AS400JDBCConnection object.</p>
<div class="note"><span class="notetitle">Note:</span> When
connections are not returned to the pool, the connection pool continues to
grow in size and connections are not reused.</div>
<p>Set properties on the
pool by using methods inherited from <a href="javadoc/com/ibm/as400/access/ConnectionPool.html"> ConnectionPool</a>. Some of the properties that you can
set include:</p>
<ul><li>maximum number of connections to allow in the pool</li>
<li>maximum lifetime of a connection</li>
<li>maximum inactivity time of a connection.</li>
</ul>
<p>You can also register AS400JDBCConnectionPoolDataSource objects by
using a Java Naming and Directory Interface<sup>(TM)</sup> (JNDI)
service provider. For more information on JNDI service providers, see <a href="reflearn.htm#reflearn">IBM Toolbox for Java reference links</a>.</p>
</div>
<div class="section" id="jdbcconnpool__jdbcconex"><a name="jdbcconnpool__jdbcconex"><!-- --></a><h4 class="sectiontitle">Example: Using connection pool</h4><p>The
following example gets a connection pool data source from JNDI and uses it
to create a connection pool with 10 connections:</p>
<pre> // Obtain an AS400JDBCConnectionPoolDataSource object from JNDI
// (assumes JNDI environment is set).
Context context = new InitialContext(environment);
AS400JDBCConnectionPoolDataSource datasource =
(AS400JDBCConnectionPoolDataSource)context.lookup("jdbc/myDatabase");
// Create an AS400JDBCConnectionPool object.
AS400JDBCConnectionPool pool = new AS400JDBCConnectionPool(datasource);
// Adds 10 connections to the pool that can be used by the
// application (creates the physical database connections based on
// the data source).
pool.fill(10);
// Get a handle to a database connection from the pool.
Connection connection = pool.getConnection();
... Perform miscellaneous queries/updates on the database.
// Close the connection handle to return it to the pool.
connection.close();
... Application works with some more connections from the pool.
// Close the pool to release all resources.
pool.close();</pre>
</div>
</div>
</body>
</html>