Monday, 18 September 2017

Testing JDBC Data Sources using Jython

One of my colleagues asked me about this …

In essence, did I have a Jython script that allows one to test JDBC data source …

Here's one I prepared earlier: -

testDataSource.jy

cellID = AdminControl.getCell()
cell=AdminConfig.getid( '/Cell:'+cellID+'/')
for dataSource in AdminConfig.list('DataSource',cell).splitlines():
 print dataSource
 AdminControl.testConnection(dataSource)


Notes: -

- To support the FOR loop, there are indentations ( thanks Python, we love you ) in front of the last two lines of the script
- Similarly, there's a spare, blank line ( again, thanks, Python ) at the end of the script to finish the loop

When I run this: -

I do get an exception, for which I'm NOT catching: -


specifically this: -

DefaultEJBTimerDataSource(cells/PCCell1/applications/commsvc.ear/deployments/commsvc|resources.xml#DataSource_1228749623069)
WASX7017E: Exception received while running file "testDataSource.jy"; exception information: com.ibm.websphere.management.exception.AdminException
javax.management.MBeanException
java.sql.SQLException: java.sql.SQLException: Database '/opt/ibm/WebSphereProfiles/AppSrv01/databases/EJBTimers/AppClusterMember1/EJBTimerDB' not found. DSRA0010E: SQL State = XJ004, Error Code = 40,000


I could mitigate that by adding the appropriate try/catch logic to my script - that's tomorrow's challenge.

For the record, this exception occurs against a datasource about which I don't care :-)

No comments: