The test connection service enables developers to test a connection to a data source.
There are several ways to test a connection to a database that uses the parameters defined in a data source in WebSphere Application Server - Express. 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 - Express 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 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.
See Testing a connection with the administrative console for more information.
Wsadmin tool
The wsadmin tool provides a scripting interface to a full range of WebSphere Application Server - Express administration activities. Because the Test Connection functionality is implemented as a method on an MBean, and wsadmin can invoke MBean methods, wsadmin can be used to test connections to DataSources. There are three ways to test data source connections from wsadmin:
Using the testConnection operation in the AdminControl object of wsadmin. This operation tests the configuration properties of a data source object. See Testing a connection using wsadmin for more information.
Using the testConnection facility in wsadmin. See Example: Migrating - Testing the DataSource object connection for more information.
Invoking the MBean operation. See Example: Testing data source connection using wsadmin for more information.
Java stand alone program
The test connection commands can also be invoked from a Java program by using Java Management Extensions (JMX) to connect directly to the MBean.
The preferred way of testing connections in WebSphere Application Server - Express is invoking the test connection method through a Java program. The advantage to this method is that you can pass the configuration ID of a configured data source, rather than the properties of the data source. The Java program uses JMX to connect to a running server and invoke the testConnection method on the DataSourceCfgHelper MBean. You connect to the running server, usually on port 8880.
The return value from the invocation is zero (0), a positive number, or an exception. Zero (0) indicates that the operation successfully completed with no warnings. A positive number indicates that the operation successfully completed with the number of warnings. An exception indicates that the test of the connection failed.
See Example: Test a connection using testConnection(ConfigID) for more information about how to invoke the test connection method by passing in the configuration ID of a configured data source.
See Example: Test a connection using country and language (properties) for more information about how to invoke the test connection operation on the DataSourceCfgHelper MBean from a Java program that wsadmin uses by passing in the properties you want to test.
See Example: Test a connection to a data source for more information about how to invoke the test connection operations in previous releases of WebSphere Application Server - Express.