You can test connections for data sources with the wsadmin tool and scripting. After you have defined and saved a data source, you can test the data source connection to ensure that the parameters in the data source definition are correct.
You can use the testConnection command for the AdminControl object to test data source connections for a cell, node, server, application, or cluster scope. Use the example to test the data source connection for the application scope.
set ds [$AdminConfig getid /DataSource:DS1/]
$AdminControl testConnection $ds
ds = AdminConfig.getid('/DataSource:DS1/')
AdminControl.testConnection(ds)
Examples of output:
WASX7217I: Connection to provided datasource was successful.
DSRA0174W: Warning: GenericDataStoreHelper is being used.
WASX7015E: Exception running command: "$AdminControl testConnection
$ds1"; exception information:
com.ibm.websphere.management.exception.AdminException
javax.management.MBeanException
java.sql.SQLRecoverableException: java.sql.SQLRecoverableException: Io
exception: The Network Adapter could not establish the
connectionDSRA0010E: SQL State = 08006, Error Code = 17,002
The following example invokes the testConnectionToDataSource operation on the MBean, passing in the classname, userid, password, database name, JDBC driver class path, language, and country.
$AdminControl invoke $dshelper testConnectionToDataSource
"COM.ibm.db2.jdbc.DB2XADataSource db2admin db2admin
{{databaseName sample}} /sqllib/java/db2java.zip en US"
print AdminControl.invoke(dshelper, 'testConnectionToDataSource',
'COM.ibm.db2.jdbc.DB2XADataSource dbuser1 dbpwd1
"{{databaseName jtest1}}" /sqllib/java12/db \"\" \"\"')
Example output:
WASX7217I: Connection to provided data source was successful.
set appID [$AdminConfig getid /Deployment:myApplication/]
set ds [$AdminConfig list DataSource $appID]
appID = AdminConfig.getid("/Deployment:myApplication/")
ds = AdminConfig.list("DataSource", appID)
$AdminControl testConnection $ds
AdminControl.testConnection(ds)
WASX7467I: Connection to provided datasource on node myNode processnodeagent was successful.
WASX7217I: Connection to provided datasource was successful.
In the following example, the Cluster1 server cluster contains cluster members on the node1, node2, and node3 nodes. The Cluster1 server cluster contains the DSC1 data source.
set cluster [$AdminConfig getid /ServerCluster:Cluster1/]
set ds [$AdminConfig list DataSource $cluster]
cluster = AdminConfig.getid("/ServerCluster:Cluster1/")
ds = AdminConfig.list("DataSource", cluster)
$AdminControl testConnection $ds
AdminControl.testConnection(ds)
WASX7467I: Connection to provided datasource on node node1 process nodeagent was successful.
WASX7467I: Connection to provided datasource on node node2 process nodeagent was successful.
WASX7467I: Connection to provided datasource on node node3 process nodeagent was successful.
WASX7217I: Connection to provided datasource was successful.