114 lines
6.4 KiB
HTML
114 lines
6.4 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="AS400JDBCDataSource class" />
|
|
<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="jdbcdatasource" />
|
|
<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>AS400JDBCDataSource class</title>
|
|
</head>
|
|
<body id="jdbcdatasource"><a name="jdbcdatasource"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">AS400JDBCDataSource class</h1>
|
|
<div><p></p>
|
|
<div class="section"><p>The <a href="javadoc/com/ibm/as400/access/AS400JDBCDataSource.html"> AS400JDBCDataSource</a> class represents a factory for iSeries™ database
|
|
connections. The <a href="javadoc/com/ibm/as400/access/AS400JDBCConnectionPoolDataSource.html#NAVBAR_TOP"> AS400JDBCConnectionPoolDataSource</a> class represents a
|
|
factory for <a href="javadoc/com/ibm/as400/access/AS400JDBCPooledConnection.html#NAVBAR_TOP"> AS400JDBCPooledConnection</a> objects. </p>
|
|
<p>You can register
|
|
either kind of data source object by using a Java™ Naming and Directory Interface (JNDI)
|
|
service provider. For more information about JNDI service providers, see <a href="reflearn.htm#reflearn">IBM<sup>®</sup> Toolbox for Java reference links</a>.</p>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Examples</h4><p>The following examples demonstrate ways
|
|
to create and use AS400JDBCDataSource objects. The last two examples show
|
|
how to register an AS400JDBCDataSource object with JNDI and then use the
|
|
object returned from JNDI to obtain a database connection. Notice that even
|
|
when using different JNDI service providers, the code is very similar.</p>
|
|
</div>
|
|
<div class="section"><p><strong>Example: Creating an AS400JDBCDataSource object</strong></p>
|
|
<p>The
|
|
following example shows you how to create an AS400JDBCDataSource object and
|
|
connect it to a database:</p>
|
|
<pre> // Create a data source for making the connection.
|
|
AS400JDBCDataSource datasource = new AS400JDBCDataSource("myAS400");
|
|
datasource.setUser("myUser");
|
|
datasource.setPassword("MYPWD");
|
|
|
|
// Create a database connection to the iSeries.
|
|
Connection connection = datasource.getConnection();</pre>
|
|
</div>
|
|
<div class="section"><p> <strong>Example: Creating an AS400JDBCConnectionPoolDataSource object
|
|
that can be used to cache JDBC connections</strong></p>
|
|
<p>The following example
|
|
shows how you can use an AS400JDBCConnectionPoolDataSource to cache JDBC connections.</p>
|
|
<pre> // Create a data source for making the connection.
|
|
AS400JDBCConnectionPoolDataSource dataSource = new AS400JDBCConnectionPoolDataSource("myAS400");
|
|
datasource.setUser("myUser");
|
|
datasource.setPassword("MYPWD");
|
|
|
|
// Get the PooledConnection.
|
|
PooledConnection pooledConnection = datasource.getPooledConnection();</pre>
|
|
</div>
|
|
<div class="section"><p> <strong>Example: Using JNDI service provider classes to store an AS400JDBCDataSource
|
|
object</strong></p>
|
|
<p>The following example shows how you can use JNDI service
|
|
provider classes to store a DataSource object directly to the integrated file
|
|
system on the server:</p>
|
|
<pre> // Create a data source to the iSeries database.
|
|
AS400JDBCDataSource dataSource = new AS400JDBCDataSource();
|
|
dataSource.setServerName("myAS400");
|
|
dataSource.setDatabaseName("myAS400 Database");
|
|
|
|
// Register the datasource with the Java Naming and Directory Interface (JNDI).
|
|
Hashtable env = new Hashtable();
|
|
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
|
|
Context context = new InitialContext(env);
|
|
context.bind("jdbc/customer", dataSource);
|
|
|
|
// Return an AS400JDBCDataSource object from JNDI and get a connection.
|
|
AS400JDBCDataSource datasource = (AS400JDBCDataSource) context.lookup("jdbc/customer");
|
|
Connection connection = datasource.getConnection("myUser", "MYPWD");</pre>
|
|
</div>
|
|
<div class="section"><p> <strong>Example: Using AS400JDBCDataSource objects and IBM SecureWay
|
|
Directory classes with a Lightweight Directory Access Protocol (LDAP) directory
|
|
server</strong></p>
|
|
<p>The following examples shows how you can use IBM SecureWay<sup>®</sup> Directory
|
|
classes to store an object to a Lightweight Directory Access Protocol (LDAP)
|
|
directory server:</p>
|
|
<pre> // Create a data source to the iSeries database.
|
|
AS400JDBCDataSource dataSource = new AS400JDBCDataSource();
|
|
dataSource.setServerName("myAS400");
|
|
dataSource.setDatabaseName("myAS400 Database");
|
|
|
|
// Register the datasource with the Java Naming and Directory Interface (JNDI).
|
|
Hashtable env = new Hashtable();
|
|
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.jndi.LDAPCtxFactory");
|
|
Context context = new InitialContext(env);
|
|
context.bind("cn=myDatasource, cn=myUsers, ou=myLocation,o=myCompany,c=myCountryRegion",
|
|
dataSource);
|
|
|
|
// Return an AS400JDBCDataSource object from JNDI and get a connection.
|
|
AS400JDBCDataSource datasource = (AS400JDBCDataSource) context.lookup(
|
|
"cn=myDatasource, cn=myUsers, ou=myLocation,o=myCompany,c=myCountryRegion");
|
|
Connection connection = datasource.getConnection("myUser", "MYPWD");</pre>
|
|
</div>
|
|
</div>
|
|
|
|
</body>
|
|
</html> |