Example: Creating a JDBC provider and data source using Java Management Extensions API and the scripting tool

Following is a JACL (WSadmin - scripting tool) script used to create a data source and test the connection. This script:

# Following is a JACL (WSadmin - scripting tool) script used to create a data source and test the connection. 3 This script:
#   Creates a data source fvtDS_1 
#   Creates a container-managed persistence (CMP) data source linked to fvtDS_1 

# The classpath that will be used by your database driver
set driverClassPath "/db2beta/db2710/classes/db2j2classes.zip"
set driverNativePath "/db2beta/db2710/lib"

set server "server1"

set fvtbase "c:/wssb/fvtbase"

# Users and passwords..
set defaultUser "IBMUSER"
set defaultPassword "IBMUSER"
set aliasName "IBMUSER"

set databaseName "LOC1"

puts "Add an alias alias1"
set cell [$AdminControl getCell]  
set sec [$AdminConfig getid /Cell:$cell/Security:/]

#---------------------------------------------------------
# Create a JAASAuthData object for component-managed authentication 
#---------------------------------------------------------

puts "create JAASAuthData object for alias1" 

set alias_attr    [list alias $aliasName]
set desc_attr     [list description "Alias 1"]
set userid_attr   [list userId $defaultUser]
set password_attr [list password $defaultPassword]
set attrs [list $alias_attr $desc_attr $userid_attr $password_attr]

set authdata [$AdminConfig  create JAASAuthData $sec $attrs] 
$AdminConfig save

puts "Installing DB2 for zOS Local JDBC Provider (RRS) DataSource"

#Get the server name...
puts "Finding the server $server"

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 "Found server $srvr"
    set serv $srvr
  }
}

puts "Finding the Resource Adapter"
set rsadapter [$AdminConfig list J2CResourceAdapter $serv]

#Now create a JDBC Provider for the 5.0 data sources
puts "Creating the provider for com.ibm.db2.jcc.DB2ConnectionPoolDataSource"
set attrs1 [subst {{classpath $driverClassPath} {nativepath $driverNativePath} {implementationClassName com.ibm.db2.jcc.DB2ConnectionPoolDataSource} {name "FVTProvider2"} {description "DB2 JDBC Provider"} {xa "true"}}]
set provider1 [$AdminConfig create JDBCProvider $serv $attrs1]

#Create the first data source
puts "Creating the datasource fvtDS_1"
set attrs2 [subst {{name fvtDS_1} {description "FVT DataSource 1"}}]
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 $databaseName}}]
$AdminConfig create J2EEResourceProperty $propSet1 $attrs3

set attrs10 [subst {{jndiName jdbc/fvtDS_1} {statementCacheSize 10} {datasourceHelperClassname com.ibm.websphere.rsadapter.DB2DataStoreHelper} {relationalResourceAdapter {$rsadapter}} {authMechanismPreference "BASIC_PASSWORD"} {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 we will add a connection factory for the CMPs..
puts "Creating the CMP Connector Factory for fvtDS_1"
set attrs12 [subst {{name "FVT DS 1_CF"} {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 "DefaultPrincipalMapping"} {authDataAlias "alias1"}}

$AdminConfig save

Related concepts
Resource adapter
Connection factory
JDBC providers
Data sources
Connection pooling



Searchable topic ID:   scriptool
Last updated: Jun 21, 2007 9:56:50 PM CDT    WebSphere Application Server for z/OS, Version 5.0.2
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.websphere.zseries.doc/info/zseries/ae/rdat_scriptool.html

Library | Support | Terms of Use | Feedback