Loading

Properly Disposing DB2 driver

Udgivelsesdato: Jan 10, 2025
Løsning

PROBLEM

When connecting to db2 DB using DB connector, one can add the driver to the lib/user folder of the MULE ESB server. This is done to avoid having to package the driver to every application that will be deployed in the server. If the DB connector configuration is not done properly this can result in a not clean dispose of the DB2 driver when undeploying the application.

SYMPTOM

When an application that uses the db2 driver shared in /lib/user folder is deployed, undeployed and then deployed again, In this second deploy when the flow is exercised it will result in error:

java.sql.SQLException: Cannot get connection for URL ${boss.datasource.url} : No suitable driver found for ${boss.datasource.url}
at org.enhydra.jdbc.standard.StandardDataSource.getConnection(StandardDataSource.java:216)
at org.enhydra.jdbc.standard.StandardDataSource.getConnection(StandardDataSource.java:144)
at org.mule.module.db.internal.domain.connection.SimpleConnectionFactory.doCreateConnection(SimpleConnectionFactory.java:26)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

 

CAUSE

The issue happens when the db2 driver is not properly configured to be disposed when the application is undeployed.
 

  <db:generic-config name="BOSS_Database" 
    url="${boss.datasource.url}" 
    driverClassName="com.ibm.db2.jcc.DB2Driver"  
    doc:name="Generic Database Configuration" />   

SOLUTION

Use the following configuration to ensure that the DB2 driver will be disposed properly. The key point is to set the "destroy-method" so it is invoked when the application is undeployed.

<spring:beans>
        <spring:bean id="db2DataSource" name="db2DataSource" class="com.ibm.db2.jcc.DB2DataSource" destroy-method="finalize">
            <spring:property name="serverName" value="127.0.0.1"/>
            <spring:property name="portNumber" value="51620"/>
            <spring:property name="databaseName" value="TEST"/>
            <spring:property name="driverType" value="4"/>
            <spring:property name="user" value="test"/>
            <spring:property name="password" value="test"/>
            <spring:property name="sslConnection" value="true"/>
            <spring:property name="sslTrustStoreLocation" value="C:\db2_ssl\db2.jks"/>
            <spring:property name="sslTrustStorePassword" value="test123"/>
        </spring:bean>
    </spring:beans>


 <db:generic-config name="DB2_Database" 
    driverClassName="com.ibm.db2.jcc.DB2Driver"  
    doc:name="Generic Database Configuration" dataSource-ref="db2DataSource"/>    

 


 

Vidensartikelnummer

001118965

 
Indlæser
Salesforce Help | Article