with HikariCP it is possible to change Username and Password of the whole pool at runtime. You only have to set a poolName and set registerMbeans to true during the creation of the pool. At runtime you could then use MXBeanProxy to change Username and password at runtime. It looks like this:
public void changeUser(HikariDataSource ds, String newUser, String newPassword) {
HikariConfigMXBean configBean = ds.getHikariConfigMXBean();
configBean.setUsername(user);
configBean.setPassword(password);
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName poolName= new ObjectName("com.zaxxer.hikari:type=Pool (" + dbKey + ")");
HikariPoolMXBean poolProxy = JMX.newMXBeanProxy(mBeanServer, poolName,
HikariPoolMXBean.class);
poolProxy.softEvictConnections();
}
But now I search some similar code for the Tomcat Connection Pool. Or another method to change username and password of Tomcat Connection Pool at runtime.
I hope somebody have an idea.