Search code examples
jdbcwebspherejmx

Retrieving Datasource JDBC connection string via JMX from IBM Websphere


I would like to know if it is possible to retrieve a Datasource's JDBC connection String from IBM Websphere Application Server. I already have access to the datasource's JMX Bean but no attribute or operation (see below) seems to expose the JDBC connection URL String. Does anybody know how to retrieve this information?

Attributes:

dbcDriver: WebSphere:name=...
connectionFactoryType: interface javax.sql.DataSource
dataSourceName: 
dataStoreHelperClass: description: New JDBC Datasource
loginTimeout: statementCacheSize: 10
jtaEnabled: true
testConnection: true
testConnectionInterval: 180
objectName: WebSphere:name=...
stateManageable: false
statisticsProvider: false
eventProvider: false
authMechanismPreference: 0
stuckTimerTime: 0
stuckTime: 0
stuckThreshold: 0
surgeThreshhold: -1
surgeCreationInterval: 0
connectionTimeout: 180
maxConnections: 10
minConnections: 1
purgePolicy: FailingConnectionOnly
reapTime: 180
unusedTimeout: 1800
agedTimeout: 0
freePoolDistributionTableSize: 5
freePoolPartitions: 1
sharedPoolPartitions: 200
holdTimeLimit: 10
diagnosticProviderName: ...
name: TaggingDatenquelle
Description: New JDBC Datasource
jndiName: jdbc/name
category: 

Operations:

getJdbcDriver: 
getConnectionFactoryClass: 
getDataSourceName: 
getDataStoreHelperClass: 
getDescription: 
getLoginTimeout: 
getStatementCacheSize: 
isJTAEnabled: 
getProperty: 
getTestConnection: 
setTestConnection: 
getTestConnectionInterval: 
setTestConnectionInterval: 
getObjectNameStr: 
isStateManageable: 
isStatisticsProvider: 
isEventProvider: 
getAuthMechanismPreference: 
getStuckTimerTime: 
setStuckTimerTime: 
getStuckTime: 
setStuckTime: 
getStuckThreshold: 
setStuckThreshold: 
getSurgeThreshhold: 
setSurgeThreshhold: 
getSurgeCreationInterval: 
setSurgeCreationInterval: 
getConnectionTimeout: 
setConnectionTimeout: 
getMaxConnections: 
setMaxConnections: 
getMinConnections: 
setMinConnections: 
getPurgePolicy: 
setPurgePolicy: 
getReapTime: 
setReapTime: 
getUnusedTimeout: 
setUnusedTimeout: 
getAgedTimeout: 
setAgedTimeout: 
getFreePoolDistributionTableSize: 
getFreePoolPartitions: 
getSharedPoolPartitions: 
getHoldTimeLimit: 
setHoldTimeLimit: 
showPoolContents: 
showAllPoolContents: 
purgePoolContents: 
purgePoolContents: 
purgePoolContents: 
getPoolContents: 
getAllPoolContents: 
showAllocationHandleList: 
pause: 
resume: 
getStatus: 
getDiagnosticProviderName: 
getDiagnosticProviderId: 
getRegisteredDiagnostics: 
configDump: 
stateDump: 
selfDiagnostic: 
localize: 
getName: 
getDescription: 
getJndiName: 
getCategory: 

=====================================

Solution

  • In short, no you can not get the connection URL from any of the currently provided JMX beans.

    The only way that WebSphere Liberty exposes the JDBC connection URL is thorugh the java.sql.DatabaseMetaData.getURL() API. If you can get a reference to a DataSource object (via JNDI lookup or @Resource injection), you can get a connection from that, get the DatabaseMetaData and then call getURL().

    DataSource ds = (DataSource) new InitialContext().lookup("jdbc/name");
    String url = ds.getConnection().getMetaData().getURL();