JDBC providers

 

+

Search Tips   |   Advanced Search

 


Contents

  1. Overview
  2. Configure using the console
  3. Settings
  4. Configure using wsadmin
  5. Create using JME API and wsadmin.sh

 


Overview

J2EE apps use JDBC providers and data sources to access data from relational databases.

The J2EE Connector Architecture connection factory that is used by the relational resource adapters is constructed by combining a JDBC provider with a data source.

To create a J2EE Connector Architecture connection factory.

  1. Create a JDBC provider
  2. Create a data source
  3. Bind the resource reference.
  4. Test the connection.

 


Configure a JDBC provider using the console

  1. Open the administrative console and go to...

    Admin console | Resources | JDBC Providers
    ...select the scope of your definition, and press New.

  2. Use the drop-down box to select your JDBC provider, or select the User-Defined JDBC Provider to define your own. Avoid changing the name of existing JDBC providers.

  3. Enter the properties for your JDBC provider

  4. Set up a data source.

 


JDBC provider settings

Go to...

Resources | JDBC Providers | JDBC_provider

...and set...

Scope Visibility level of resource:

Cell Most general. Visible from all Nodes and servers, unless overridden by a more specific scope.
Node Default scope. Visible to all servers on the same node, unless they are overridden at a server scope.
Server Most specific scope.

Name Name of the resource provider.
Description Text description for the resource provider.
Classpath List of paths or JAR file names which together form the location for the resource provider classes. For example...

/SQLLIB/java/db2java.jar

or

/usr/local/appname/lib/classes12.jar

Classpath entries are separated by using the ENTER key and must not contain path separator characters (such as ';' or ':'). You can use variables.

Native Library Path Location for resource provider native libraries.

Native path entries are separated by using the ENTER key and must not contain path separator characters (such as ';' or ':'). You can use variables.

Implementation Classname Java class name of the JDBC driver implementation.

This class is available in the driver file mentioned in the Classpath description above.

 


Configure a JDBC provider using wsadmin

### Identify the parent ID and assign it to the 
### node variable  

set node [$AdminConfig  getid  /Cell:cell/Node:node/]


###
### Identify the required attributes...

$AdminConfig required JDBCProvider


###
### Set up the required attributes and assign it 
### to the jdbcAttrs variable

set n1        [list name myProviderName]
set c1        [list implementationClassName myclass]
set jdbcAttrs [list $n1 $c1]


###
###  Create a new JDBC provider using node as the parent...

$AdminConfig create JDBCProvider $node $jdbcAttrs

$AdminConfig save

 


Create a JDBC provider and data source using JME API and wsadmin.sh


###
### Set up XA DB2 data sources
###

puts "Setting up XA DB2 datasource..."

set driverClassPath  "/usr/local/clustername/config/lib/db2java.zip"
set server           "server"
set fvtbase          "/wssb/fvtbase"
set user1            "dbuser1"
set password1        "dbpwd1"
set aliasName        "testalias"
set vtestDB          "testDB"


puts "Creating JAASAuthData object for testalias..." 
set cell [$AdminControl getCell]  
set sec [$AdminConfig getid /Cell:$cell/Security:/]


set alias_attr    [list alias       $aliasName]
set desc_attr     [list description "My Unique Alias"]
set userid_attr   [list userId      $user1]
set password_attr [list password    $password1]
set attrs         [list $alias_attr $desc_attr $userid_attr $password_attr]

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



puts "Finding the old JDBCProvider..."

set jps [$AdminConfig list JDBCProvider]

foreach jp $jps 
{
 set jpname [lindex [lindex [$AdminConfig show $jp {name}] 0] 1]

 if {($jpname == "FVTProvider")} 
 {

  puts "Removing old JDBC Provider..."

  $AdminConfig remove $jp
  $AdminConfig save
 }
}


###
### 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.jdbc.DB2XADataSource ..."

set attrs1 [subst {{classpath $driverClassPath} \
                   {implementationClassName COM.ibm.db2.jdbc.DB2XADataSource} \
                   {name "FVTProvider2"} \
                   {description "DB2 JDBC Provider"}}]
set provider1 [$AdminConfig create JDBCProvider $serv $attrs1]


###
### Create the first data source
###

puts "Creating the datasource testDS ..."

set attrs2 [subst {{name testDS} {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 $vtestDB}}]
$AdminConfig create J2EEResourceProperty $propSet1 $attrs3

set attrs10 [subst {{jndiName jdbc/testDS} \
                    {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} }




###
### Add a connection factory for the CMPs..
###

puts "Creating the CMP Connector Factory for testDS"

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 "testalias"}}

$AdminConfig save