I am stuck in a problem related to data source objects in java. I set the data source connection parameters in the data source object (org.apache.tomcat.jdbc.pool.DataSource). I want to get these parameters from a data source object before I call the getConnection method method containing meaningful debugging information inside catch if it catches an exception.
Below is the code I tried. I can get all connection parameters from metadata as follows: [ex: - connection.getMetaData (). GetURL ()], but I want to catch the exception and log url, password, username as a log if getConnection () throws an exception. Therefore, I need to get this information from the data source object before it tries to create a db connection.
try {
When I remove debugging, I get the data source object as follows.
org.apache.tomcat.jdbc.pool.DataSource@d47feb3 {ConnectionPool[defaultAutoCommit=null; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=com.mysql.jdbc.Driver; maxActive=100; maxIdle=8; minIdle=0; initialSize=0; maxWait=30000; testOnBorrow=false; testOnReturn=false; timeBetweenEvictionRunsMillis=5000; numTestsPerEvictionRun=0; minEvictableIdleTimeMillis=60000; testWhileIdle=false; testOnConnect=false; password=********; url=jdbc:mysql://localhost/wso2_mb_1; username=a; validationQuery=null; validationQueryTimeout=-1; validatorClassName=null; validationInterval=30000; accessToUnderlyingConnectionAllowed=true; removeAbandoned=false; removeAbandonedTimeout=60; logAbandoned=false; connectionProperties=null; initSQL=null; jdbcInterceptors=ConnectionState;StatementFinalizer;org.wso2.carbon.ndatasource.rdbms.ConnectionRollbackOnReturnInterceptor;; jmxEnabled=true; fairQueue=true; useEquals=true; abandonWhenPercentageFull=0; maxAge=0; useLock=false; dataSource=null; dataSourceJNDI=null; suspectTimeout=0; alternateUsernameAllowed=false; commitOnReturn=false; rollbackOnReturn=false; useDisposableConnectionFacade=true; logValidationErrors=false; propagateInterruptState=false; ignoreExceptionOnPreLoad=false; }
I see all url, username and password parameters, but I can not get them. Is there a way to get these values โโfrom a data source object.
source share