Retrieving Datasource Name with iBatis on Spring Framework on WebSphere Application Server 6.2.X

I' ve used the following code sample in order to retrieve the name of datasource that is used by our bean (SqlMapClientTemplate) to access the database. I am using Rational Software Architect 7.5.X.

// Import statements 
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
import java.lang.reflect.Field;

// ... WHATEVER ...
try {
 TransactionAwareDataSourceProxy proxyDatasource = (TransactionAwareDataSourceProxy) getSqlMapClientTemplate().getSqlMapClient().getDataSource();
 WSJdbcDataSource dataSource =  (WSJdbcDataSource) proxyDatasource.getTargetDataSource();

 Field dataSourceField = dataSource.getClass().getDeclaredField("cm");
 Object fieldValue = dataSourceField.get(dataSource);
 System.err.println("# DataSource Details:" + fieldValue);
} catch (Exception e) {
      System.err.println("Exception occured while retrieving datasource details. Details: " + e.getMessage());  


Popular posts from this blog

SoapUI 4.5.0 Project XML File Encoding Problem

COMRESET failed (errno=-32)

SoapUI - Dynamic Properties - Getting Current Time in DateTime Format