Jump to content
We have recently updated our Privacy Statement, available here ×
  • Using DataSource to create JDBC Connection

    Manoj Chaurasia

    Table of Contents

    For most applications that need to use JDBC, the default behavior of TIBCO ActiveMatrix BusinessWorks? when creating JDBC connections is to use the DriverManager class to create a connection object. The process involves calling a synchronized method named "getConnection", which could cause performance issues in some cases if the call gets blocked. To avoid such a risk, applications can use the DataSource interface. The DataSource interface was introduced in the JDBC 2.0 Optional Package which is now available as part of the J2SE 1.4.0 FCS.

    A JDBC driver that implements the DataSource interface returns connections that implement the Connection interface in much the same way as Connection objects are returned by the DriverManager class. Using the DataSource interface also improves application portability by allowing a logical name for a data source while removing the need to tie down information to a particular driver thereby avoiding the synchronization currently present in the DriverManager class.

    Configuring ActiveMatrix BusinessWorks to Use a DataSource

    ActiveMatrix BusinessWorks JDBC Shared Connection allows you to configure a DataSource, but it requires a JNDI Server to maintain the DataSources. In cases where is not available and the application needs to use DataSource to get JDBC Connections, ActiveMatrix BusinessWorks provides a property that allows you to switch to DataSource.

    By setting the property "bw.plugin.jdbc.connection.useDatasource=true" in the deployed ActiveMatrix BusinessWorks Engine?s .tra file, ActiveMatrix BusinessWorks will attempt to use DataSource to get JDBC Connection. If it fails, an error message will be logged. This should work with all ActiveMatrix BusinessWorks-supported JDBC Drivers.

    Custom DataSource for Unsupported Drivers

    For unsupported drivers, the user needs to provide the DataSource class name. The property that sets the driver class name is "bw.plugin.jdbc.customDSClass" and is used as follows:

     bw.plugin.jdbc.customDSClass.{driver class name}={DataSource Class name}

    For example,

     bw.plugin.jdbc.customDSClass.com.ibm.as400.access.AS400JDBCDriver                               = com.ibm.as400.access.AS400JDBCDataSource.

    Assumptions and Avoiding Common Errors

    An important assumption the user must consider is that all properties specified by the connection URL (name-value pairs) are string-based (i.e. boolean and numeric properties will not work). When using a custom driver/DataSource, ActiveMatrix BusinessWorks typically employs Reflection to call the appropriate APIs to load the DataSource and point it at the URL provided in the JDBC Connection.

    Internally the code tries to set the connection URL by calling a 'setURL' API on the loaded DataSource.If this fails, it will break the connection URL and instead call APIs which are specific to the drivers. This behavior is expected by all drivers/DataSources. In the following example, the connection URL is calling the API 'setdatabaseName' with model as its value.


    The API is proven to be wrong, resulting in a 'NoSuchMethodException' because the method name specified in the URL is wrong. The correct method to call is 'setDatabaseName'.

    If you change the URL from



     jdbc:microsoft:sqlserver:// server:1433;DatabaseName=model

    it should work correctly.

    To work around the limitation of using only string-based properties, one can write a wapper for the original DataSource. This way, any DataSource can be customized for use in ActiveMatrix BusinessWorks?.


    Microsoft sqlserver driver has a boolean property named 'SendStringParametersAsUnicode'. If you need to set this property with DataSource implementation, it would fail with the error below since only string-based properties are supported in ActiveMatrix BusinessWorks?.

     java.lang.NoSuchMethodException: com.microsoft.jdbcx.sqlserver.SQLServerDataSource.setSendStringParametersAsUnicode(java.lang.String)

    To work around this error, you must treat the DataSource as a custom DataSource by setting the following:

     bw.plugin.jdbc.connection.useDatasource=true  bw.plugin.jdbc.customDSClass.com.microsoft.jdbc.sqlserver.SQLServerDriver=com.tibco.example.wrapper.SQLServerDSWrapper

    A wrapper class that extends the actual DataSource can be written as the one shown here. Create a jar file of this class and place it under /tibco/tpcl/5.x/jdbc.

    Encountered Issues?

    Contact support@tibco.com with the following information:

    • ActiveMatrix BusinessWorks Project repository
    • The deployed engine's .tra fie
    • The database and driver versions
    • If required, the DB scripts to create the necessary tables

    User Feedback

    Recommended Comments

    There are no comments to display.

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

  • Create New...