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 com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource; import java.lang.reflect.Field; // ... WHATEVER ... try { TransactionAwareDataSourceProxy proxyDatasource = (TransactionAwareDataSourceProxy) getSqlMapClientTemplate().getSqlMapClient().getDataSource(); WSJdbcDataSource dataSource = (WSJdbcDataSource) proxyDatasource.getTargetDataSource(); Field dataSourceField = dataSource.getClass().getDeclaredField("cm"); dataSourceField.setAccessible(true); Object fieldValue = dataSourceField.get(dataSource); dataSourceField.setAccessible(false); System.err.println("# DataSource Details:" + fieldValue); } catch (Exception e) { System.err.println("Exception occured while retrieving datasource details. Details: " + e.getMessage()); }
Comments
Post a Comment
Thx for reading! Comments are appreciated...