从IBM Websphere通过JMX检索数据源JDBC连接字符串

时间:2015-10-02 09:49:08

标签: jdbc websphere jmx

我想知道是否可以从IBM Websphere Application Server检索Datasource的JDBC连接字符串。我已经可以访问数据源的JMX Bean,但是没有任何属性或操作(见下文)似乎公开了JDBC连接URL String。有人知道如何检索这些信息吗?

属性:

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: 

操作:

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: 

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

1 个答案:

答案 0 :(得分:0)

简而言之,您无法从任何当前提供的JMX bean获取连接URL。

WebSphere Liberty公开JDBC连接URL的唯一方法是使用java.sql.DatabaseMetaData.getURL() API。如果您可以获得对DataSource对象的引用(通过JNDI查找或@Resource注入),您可以从中获取连接,获取DatabaseMetaData然后调用getURL()

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