ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzatz_5.4.0.1/51/program/dataexcrtjdbc.htm

155 lines
6.0 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK rel="stylesheet" type="text/css" href="../../../rzahg/ic.css">
<title>Example: Creating a JDBC provider and data source using Java Management
Extensions API and the scripting tool</title>
</head>
<BODY>
<!-- Java sync-link -->
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
<h3><a name="dataexcrtjdbc"></a>Example: Creating a JDBC provider and data source using Java Management Extensions API and the scripting tool</h3>
<p>Following is a JACL (wsadmin - scripting tool) script used to create a
data source and test the connection. This script:</p>
<p>
<ul>
<li>Creates a data source fvtDS_1</li>
<li>Creates a 4.0 data source fvtDS_3</li>
<li>Creates a container-managed persistence (CMP) data source linked to fvtDS_1</li>
<li>Tests the connection</li>
</ul>
</p>
<pre>#AWE -- Set up XA DB2 data sources, both 5.0 and 4.0
#UPDATE THESE VALUES:
#The classpath that will be used by your database driver
set driverClassPath &quot;/QIBM/UserData/Java400/ext/db2_classes.jar&quot;
set server &quot;server1&quot;
#Users and passwords..
set defaultUser1 &quot;dbuser1&quot;
set defaultPassword1 &quot;dbpwd1&quot;
set aliasName &quot;alias1&quot;
set databaseName1 &quot;localhost&quot;
set databaseName2 &quot;localhost&quot;
#END OF UPDATES
puts &quot;Add an alias alias1&quot;
set cell [$AdminControl getCell]
set sec [$AdminConfig getid /Cell:$cell/Security:/]
#---------------------------------------------------------
# Create a JAASAuthData object for component-managed authentication
#---------------------------------------------------------
puts &quot;create JAASAuthData object for alias1&quot;
set alias_attr [list alias $aliasName]
set desc_attr [list description &quot;Alias 1&quot;]
set userid_attr [list userId $defaultUser1]
set password_attr [list password $defaultPassword1]
set attrs [list $alias_attr $desc_attr $userid_attr $password_attr]
set authdata [$AdminConfig create JAASAuthData $sec $attrs]
$AdminConfig save
puts &quot;Installing DB2 datasource for XA&quot;
puts &quot;Finding the old JDBCProvider..&quot;
#Remove the old jdbc provider...
set jps [$AdminConfig list JDBCProvider]
foreach jp $jps {
set jpname [lindex [lindex [$AdminConfig show $jp {name}] 0] 1]
if {($jpname == &quot;FVTProvider&quot;)} {
puts &quot;Removing old JDBC Provider&quot;
$AdminConfig remove $jp
$AdminConfig save
}
}
#Get the server name...
puts &quot;Finding the server $server&quot;
set servlist [$AdminConfig list Server]
set servsize [llength $servlist]
foreach srvr $servlist {
set sname [lindex [lindex [$AdminConfig show $srvr {name}] 0] 1]
if {($sname == $server)} {
puts &quot;Found server $srvr&quot;
set serv $srvr
}
}
puts &quot;Finding the Resource Adapter&quot;
set rsadapter [$AdminConfig list J2CResourceAdapter $serv]
#Now create a JDBC Provider for the 5.0 data sources
puts &quot;Creating the provider for com.ibm.db2.jdbc.app.DB2StdXADataSource&quot;
set attrs1 [subst {{classpath $driverClassPath}
{implementationClassName com.ibm.db2.jdbc.app.DB2StdXADataSource}
{name &quot;FVTProvider2&quot;} {description &quot;DB2 UDB for iSeries JDBC Provider&quot;}}]
set provider1 [$AdminConfig create JDBCProvider $serv $attrs1]
#Create the first data source
puts &quot;Creating the datasource fvtDS_1&quot;
set attrs2 [subst {{name fvtDS_1} {description &quot;FVT DataSource 1&quot;}}]
set ds1 [$AdminConfig create DataSource $provider1 $attrs2]
#Set the properties for the data source.
set propSet1 [$AdminConfig create J2EEResourcePropertySet $ds1 {}]
set attrs3 [subst {{name databaseName} {type java.lang.String} {value $databaseName1}}]
$AdminConfig create J2EEResourceProperty $propSet1 $attrs3
set attrs10 [subst {{jndiName jdbc/fvtDS_1} {statementCacheSize 10}
{datasourceHelperClassname com.ibm.websphere.rsadapter.DB2DataStoreHelper}
{relationalResourceAdapter $rsadapter}
{authMechanismPreference &quot;BASIC_PASSWORD&quot;} {authDataAlias $aliasName}}]
$AdminConfig modify $ds1 $attrs10
#Create the connection pool object...
$AdminConfig create ConnectionPool $ds1 {{connectionTimeout 1000}
{maxConnections 30} {minConnections 1} {agedTimeout 1000} {reapTime 2000} {unusedTimeout 3000} }
#Now lets create the 4.0 data sources..
puts &quot;Creating the 4.0 datasource fvtDS_3&quot;
set ds3 [$AdminConfig create WAS40DataSource $provider1 {{name fvtDS_3}
{description &quot;FVT 4.0 DataSource&quot;}}]
#Set the properties on the data source
set propSet3 [$AdminConfig create J2EEResourcePropertySet $ds3 {}]
#These attributes should be the same as fvtDS_1
set attrs4 [subst {{name user} {type java.lang.String} {value $defaultUser1}}]
set attrs5 [subst {{name password} {type java.lang.String} {value $defaultPassword1}}]
$AdminConfig create J2EEResourceProperty $propSet3 $attrs3
$AdminConfig create J2EEResourceProperty $propSet3 $attrs4
$AdminConfig create J2EEResourceProperty $propSet3 $attrs5
set attrs10 [subst {{jndiName jdbc/fvtDS_3} {databaseName $databaseName1}}]
$AdminConfig modify $ds3 $attrs10
$AdminConfig create WAS40ConnectionPool $ds3 {{orphanTimeout 3000}
{connectionTimeout 1000} {minimumPoolSize 1} {maximumPoolSize 10} {idleTimeout 2000}}
#Now we will add a connection factory for the CMPs..
puts &quot;Creating the CMP Connector Factory for fvtDS_1&quot;
set attrs12 [subst {{name &quot;FVT DS 1_CF&quot;}
{authMechanismPreference BASIC_PASSWORD} {cmpDatasource $ds1} {authDataAlias $aliasName}}]
set cf1 [$AdminConfig create CMPConnectorFactory $rsadapter $attrs12]
#Set the properties for the data source.
$AdminConfig create MappingModule $cf1 {{mappingConfigAlias &quot;DefaultPrincipalMapping&quot;}
{authDataAlias &quot;alias1&quot;}}
$AdminConfig save</pre>
<p><strong>Note: </strong>Example may be wrapped for display purposes.</p>
</body>
</html>