[Version 5.0.1 and later]Test connection

WebSphere Application Server provides a test connection service for validating data source configurations. The testConnection operation instantiates the data source configuration, gets a connection, and then immediately closes the connection.

There are three ways to test a connection to a database that uses the parameters defined in a data source in the WebSphere Application Server. You can use the administrative console, the wsadmin tool, or a Java stand alone program. All three processes invoke the same methods on the same MBean.

Administrative console

WebSphere Application Server enables you to test a connection from the administrative console by simply pushing a button. The Data Source Collection and Data Source Details pages have new Test Connection buttons. After you have defined and saved a data source, you can click this button to ensure that the parameters in the data source definition are correct. On the collection page, you can select several data sources and test them all at once. Note that there are certain conditions that must be met first. For more information, see Testing a connection with the administrative console.

Wsadmin tool

The wsadmin tool provides a scripting interface to a full range of WebSphere Application Server administration activities. Because the Test Connection functionality is implemented as a method on an MBean, and wsadmin can invoke MBean methods, wsadmin can be utilized to test connections to DataSources. Following are the three options:

There is a testConnection facility in wsadmin that you can read about in Example: Migrating - Testing the DataSource object connection.

The AdminControl object of wsadmin has a testConnection operation that tests the configuration properties of a data source object. For information, see Testing a connection using wsadmin.

Finally, you can test a connection by invoking the MBean operation. You can find information about this by referring to Example: Testing data source connection using wsadmin.

Java stand alone program

The test connection commands can also be invoked from a Java program, by using JMX to connect directly to the MBean. For information about invoking the test connection operations before 5.0.1, see Example: Test a connection to a data source.

You can invoke the same test connection operation on the DataSourceCfgHelper MBean from a Java program that wsadmin uses, passing in the properties you want to test. You can find an example of this code here: Example: Test a connection using country and language (properties).

While both of these methods are still viable with this release, the preferred method is shown in the following paragraphs.

The new 5.0.1 test connection method can also be invoked through a Java program. The advantage is that you can pass the configuration ID of a configured data source, rather than the properties of the data source. This program uses JMX to connect to a running server and invoke the testConnection method on the DataSourceCfgHelper MBean. In a base installation, you connect to the running server, usually on port 8880.

The return value from this invocation will be either 0, a positive number, or an exception. 0 indicates that the operation completed successfully, with no warnings. A positive number indicates that the operation completed successfully, with the number of warnings. An exception indicates that the test of the connection failed.

You can find an example of this code here: Example: Test a connection using testConnection(ConfigID).


Related tasks
Testing a connection with the administrative console
Testing a connection using wsadmin
Related reference
Example: Test a connection using country and language (properties)
Example: Test a connection using testConnection(ConfigID)
Example: Migrating - Testing the DataSource object connection



Searchable topic ID:   ctestcon
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/cdat_testcon.html

Library | Support | Terms of Use | Feedback