I am migrating an app from WAS4 to WAS6.1
A piece of code is as follows:
javax.naming.Context ctx = new javax.naming.InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup(JNDI_NAME);
dsvalue_data = new Hashtable();
confvalue_data = new Hashtable();
// Parse the datasource string and get the properties
// writeInfo will return the name of the datasource and will populate the
// dsvalue_data and confvalue_data hashtables with datasource and
// connection pool properties
String tableHeader = writeInfo(ds.toString());
aResultHandler.addObject(CV_ABOUT_DESC,tableHeader);
aResultHandler.addObject(CV_ABOUT_PAGE,dsvalue_data);
.....
.....
The problem is in WAS6.1, this ds.toString()
does not give the human readable properties of the datasource
It just gives the object name (like com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource@a21fg7
) when i tried to print.
what should I do to get and print all the prope开发者_如何转开发rties of the datasource?
After obtaining your datasource ds
, you can get database information like this:
DatabaseMetaData md = ds.getConnection().getMetaData();
There are tons of methods to be used, you can get a list from official documentation.
@Pangea
In Was4,ds.toString() gives the details of the datasource in a readable format
which is then formatted to display the properties..like
errorMap = null
logOrphan = false
connTimeout = 180
TransactionBranchesLooselyCoupled = false
resetReadOnly = false
maxConnectionPoolSize = 10
autoConnectionCleanupDisabled = false
minConnectionPoolSize = 1
secureXACredential = false
surgeThreshold = -1
informixLockModeWait = 0
dataBaseVersion = 0
validationSQL = null
oracleStmtCacheSize = 0
orphanTimeout = 1800
stuckThreshold = -1
surgeTime = 20
stuckTime = 30
diagOptions = 0
connectionValidation = false
maxStatementCacheSize = 10
stuckTimerTime = 5
idleTimeout = 1800
What is your main objective? DataSource as such doesn't expose the properties your are looking for. May be you are confused by the aResultHandler API.
I will start with saying that you need to get rid of the aResultHandler API or refactor it to make use of DataSource.
If you doesn't have that option for whatever insane reason below is another option. Not sure if this works.
Depending upon the toString() was a bad choice made and hence your in this trouble. I suggest you try to cast the DataSource returned from JNDI lookup to WAS implementation class (do ds.getClass() to see what is the actual impl class) and see if these properties are exposed in some way.
精彩评论