Testing JDBC Connection when Creating or Updating JDBC Resource

You can test the connection to the configured database when you create or update the JDBC resource template from the Administrator UI or CLI. If any issues are found in the configuration, you will see a report as JDBC Test Connection FAILED. Use this feature to verify database configuration errors before the application attempts the JDBC connection. For this feature, it is not mandatory to have driver enabled on the node. ActiveMatrix Administrator can use existing third-party drivers installed using TCT or you can specify location of the drivers present on a file system or use the drivers by both the ways mentioned. You can test connection before saving the resource template by using the Test Connection button on Administrator UI.

To test the Connection from the GUI

When creating or updating a JDBC resource template, click Test Connection.

Result

If the test connection is successful, a SUCCESS message is displayed.

If the test connection fails, a failure message with error details is displayed..

To test the connection from the CLI

By default test connection is performed when creating or updating a resource template from the CLI. To disable JDBC test connection, you can use options="disableJdbcTestConnection" in the resourcetemplate_build.xml file target. For more information about TRA properties that you can configure for JDBC test connection, see TRA Properties for JDBC Test Connection.
Sample resourcetemplate_build.xml file located at <CONFIG_HOME>\admin\amxadmin\samples
<target name="create">
              <AMXAdminTask
                               remote="true"
                               propsFile="${instanceProperties}"
                               action="add"
                               dataFile="${dataFile}"
                               objectSelector="ResourceTemplate"
                               overwrite="true"
                               merge="true"
                               createIfNotExists="true"
                               force="true"
                               failOnError="false"
                               options="enableJdbcTestConnection"/>
</target>

Sample resourcetemplate_data.xml file

<ResourceTemplate
        xsi:type="amxdata:JdbcResourceTemplate"
        name="JDBC_1"
        description="jdbc non xa no tx"
        maxConnections="8888"
        disableValidateConnectionOnInit="false">

                   <Direct
                         xsi:type="amxdata:Direct"
                         dbUrl="jdbc:sqlserver://10.102.111.83:1420;databaseName=test"
                         jdbcDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver"
                         isTransactional="false"
                         loginTimeOut="2"/>
                         <InlineCredentials username="scott" password="tiger"/>

</ResourceTemplate>

Sample Output

The following is a sample output of the create target:

D:\AMX341\data_orcl\admin\amxadmin\samples>ant -f resourcetemplate_build.xml create
Buildfile: D:\AMX341_v5\data_orcl\admin\amxadmin\samples\resourcetemplate_build.xml
 
create:
[AMXAdminTask] 16 Nov 2021 20:04:02 INFO - Initializing JSSE's crypto provider class com.sun.net.ssl.internal.ssl.Provider in default mode
[AMXAdminTask] 16 Nov 2021 20:04:02 INFO - Connecting to AMX Admin server at 'http://WIN-IT4NB90F1MR:8120' as user 'root'.
[AMXAdminTask] 16 Nov 2021 20:04:03 INFO - Executing action 'add' for 1 objects from data file 'D:\AMX341_v5\data_orcl\admin\amxadmin\samples\resourcetemplate_data.xml'
[AMXAdminTask] 16 Nov 2021 20:04:04 INFO - TIBCO-AMX-CLI-000962: Getting enterprise information before executing action 'add'
[AMXAdminTask] 16 Nov 2021 20:04:04 INFO - ---------------------------------------------------------------------------------
[AMXAdminTask] 16 Nov 2021 20:04:06 INFO - ---------------------------------------------------------------------------------
[AMXAdminTask] 16 Nov 2021 20:04:06 INFO - Creating JdbcResourceTemplate : 'JDBC_Neg'
[AMXAdminTask] 16 Nov 2021 20:04:06 WARN - Test JDBC connection for database details provided for Resource template 'JDBC_Neg' has failed and Test Connection has been skipped, details of failure: SQL error occurred while making a connection to database: FATAL: password authentication failed for user "pgdb1"
[AMXAdminTask] 16 Nov 2021 20:04:07 INFO - TIBCO-AMX-CLI-000803: 'JDBC_Neg' resource template created in 'Global' scope.
[AMXAdminTask] 16 Nov 2021 20:04:07 INFO - Action finished at 11/16/21 8:04 PM in 2.413 seconds
 
BUILD SUCCESSFUL
Total time: 7 seconds

If test connection fails while creating or updating resource template from the CLI, a warning is displayed describing the test connection related issue as highlighted in the following sample output. Though the test connection fails, creating or updating resource template action is performed independent of the test result.

Log Information Specific to JDBC Test Connection

To enable the logging for this feature, enable the logger com.tibco.amx.admin.api.restemplate on SystemNode. Logs are recorded in the SystemNode.log file. SystemNode.log file is located at CONFIG_HOME\tibcohost\<instance_name>\data_3.2.x\nodes\SystemNode\logs\ directory.

Sample logs:

16 Nov 2021 15:44:44,746 [amxAdminDefaultHttpConnector_13] [TRACE] [] com.tibco.amx.admin.api.restemplate - Starting to test connection for JDBC resource template...
16 Nov 2021 15:44:44,747 [amxAdminDefaultHttpConnector_13] [TRACE] [] com.tibco.amx.admin.api.restemplate - Scanning for jdbc drivers in file system location: ''
16 Nov 2021 15:44:44,748 [amxAdminDefaultHttpConnector_13] [TRACE] [] com.tibco.amx.admin.api.restemplate - Scanning for jdbc drivers in machine model.
16 Nov 2021 15:44:44,821 [amxAdminDefaultHttpConnector_13] [DEBUG] [] com.tibco.amx.admin.api.restemplate - Successfully loaded driver class for test connection: org.postgresql.Driver
16 Nov 2021 15:44:44,979 [amxAdminDefaultHttpConnector_13] [DEBUG] [] com.tibco.amx.admin.api.restemplate - Test connection successful with Database, Database Name-PostgreSQL, Database Version- 11.6

If the primary setup has drivers installed using TCT or drivers present at the file system location or both, then the same must be configured for a replicated setup machine. If drivers that are installed on the primary machine are not available on the replicated machine, the test connection fails.