Testing data source connections using scripting

You can test connections for data sources with the wsadmin tool and scripting.

Before you begin

Before starting this task, the wsadmin tool must be running. See the Starting the wsadmin scripting client article for more information.

About this task

Perform the following steps to test a data source to ensure a connection to the database.

Procedure

  1. Identify the DataSourceCfgHelper MBean and assign it to the dshelper variable.
    • Using Jacl:
      set ds [$AdminConfig getid /DataSource:DS1/]
      $AdminControl testConnection $ds
    • Using Jython:
      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    
  2. Test the connection. 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.
    • Using Jacl:

      [AIX HP-UX Linux Solaris Windows]
      $AdminControl invoke $dshelper testConnectionToDataSource 
      "COM.ibm.db2.jdbc.DB2XADataSource db2admin db2admin 
      {{databaseName sample}} c:/sqllib/java/db2java.zip en US"
      [z/OS]
      $AdminControl invoke $dshelper testConnectionToDataSource 
      "COM.ibm.db2.jdbc.DB2XADataSource db2admin db2admin 
      {{databaseName sample}} /sqllib/java/db2java.zip en US"
    • Using Jython:

      [AIX HP-UX Linux Solaris Windows]
      print AdminControl.invoke(dshelper, 'testConnectionToDataSource',  
      'COM.ibm.db2.jdbc.DB2XADataSource dbuser1 dbpwd1 
      "{{databaseName jtest1}}" c:/sqllib/java12/db \"\" \"\"')
      [z/OS]
      print AdminControl.invoke(dshelper, 'testConnectionToDataSource',  
      'COM.ibm.db2.jdbc.DB2XADataSource dbuser1 dbpwd1 
      "{{databaseName jtest1}}" /sqllib/java12/db \"\" \"\"')



In this information ...


IBM Redbooks, demos, education, and more

(Index)

Use IBM Suggests to retrieve related content from ibm.com and beyond, identified for your convenience.

This feature requires Internet access.

Task topic Task topic    

Terms and conditions for information centers | Feedback

Last updatedLast updated: Aug 31, 2013 2:56:59 AM CDT
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=pix&product=was-nd-dist&topic=txml_testconnection
File name: txml_testconnection.html