Example: Testing data source connection using wsadmin to call a method on the MBean
The following example tests a dataSource, to ensure a connection to the database.
Note: While this method still works for Version 5.0.1, it might not work in future releases of the product.
- Identify the DataSourceCfgHelper MBean and assign it to the dshelper variable.
set dshelper [$AdminControl queryNames type=DataSourceCfgHelper,process=server1*,]Example output:
WebSphere:cell=mycell,name=DataSourceCfgHelper,mbeanIdentifier=DataSourceCfgHelper,type=DataSourceCfgHelper,node=mynode,process=server1- Test the connection.
$AdminControl invoke $dshelper testConnectionToDataSource "COM.ibm.db2.jdbc.DB2XADataSource db2admin db2admin {{databaseName sample}} c:/sqllib/java/db2java.zip en US"This example command invokes the testConnectionToDataSource operation on the MBean, passing in the classname, userid, password, database name, JDBC driver class path, language, and country.Example output:
DSRA8025I: Successfully connected to DataSource
The Preferred Method
Instead of using the method testConnectionToDataSource , use the method testConnection and pass in the configuration ID of the data source.
set myds [$AdminConfig getid "/JDBCProvider:Sybase 12.0 JDBC Driver/DataSource:sybaseds/"]$AdminControl invoke $dshelper testConnection $mydsTo aid in making a batch program, the command returns a value instead of a message. A return value of 0 means success. A return value of 1 - n means success, but with a number of warnings. If the process fails, you receive an exception message.