Test connection

 

The test connection service enables developers to test a connection to a data source.

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 version 5.0.1. One 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

The WebSphere Application Server 5.0.1 release 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 Test a connection with the administrative console.

In the Network Deploy configuration of WebSphere Application Server, the test connection operation for data sources configured at the server level is performed in the node agent of that server. Data sources configured at the nodeagent or dmgr level are tested in those processes. Because the test of the data source takes place in the node agent, it is not required that the appserver be running in order to test a connection.

 

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. Before this release, data source connections could be tested from wsadmin two ways. The 5.0.1 PTF adds a third option.

There is a testConnection facility in wsadmin that you can read about in Migrating - Test 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 Test a connection using wsadmin.

Finally, you can test a connection by invoking the MBean operation. You can find information about this by referring to Test 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 Test a connection to a data source.

One 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. One can find an example of this code here: 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.

In an ND installation, you connect to the deployment manager, usually running on port 8879. The appserver is not required to be running, you can test the connection in the node agent process by using process=nodeagent to qualify your lookup for the DataSourceCfgHelper Mbean.

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.

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


Test a connection with the administrative console
Test a connection using wsadmin
Test a connection using country and language (properties)
Test a connection using testConnection(ConfigID)

 

WebSphere is a trademark of the IBM Corporation in the United States, other countries, or both.

 

IBM is a trademark of the IBM Corporation in the United States, other countries, or both.