WebSphere Application Server provides a test connection service for testing connections to the data sources that you configure for database access.
If the definition of your data source includes WebSphere variables, see the Configuring WebSphere variables topic to verify that you define them correctly. A variable cannot be found exception results from attempted use of a data source that is configured with undefined variables.
Activating the test connection service
There are three ways to activate the test connection service: through the administrative console, the wsadmin tool, or a Java stand-alone program. Each process invokes the same methods on the same MBean.
WebSphere Application Server allows you to test a connection from the administrative console by simply pushing a button: the Data source collection, Data source settings, Version 4 data source collection, and Version 4 data source settings pages all have Test Connection buttons. After you define and save 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.
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 data sources. You have two options for testing a data source connection through wsadmin:
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.
You can also test a connection by invoking the MBean operation. Use Example: Testing data source connection using wsadmin as a guide for this technique.
Finally, you can test a connection by executing the testConnection() method on the DataSourceCfgHelper MBean. This method allows you to pass the configuration ID of the configured data source. The Java program connects to a running Java Management Extensions (JMX) server to access the MBean. In a base installation of Application Server, you connect to the JMX server running in the application server, usually on port 8880.
The return value from this invocation is 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 in Example: Test a connection using testConnection(ConfigID).
Related concepts
Variables
Related tasks
Configuring WebSphere variables
Related reference
Administrative console scope settings