I developed a spring boot restfull aplication that talk with db2 .
I used Hikari datasource for good pooling handling (maybe)
The password is taken from a safe system and for each getconnection i set the password that i recieved from the safe.
the reason why i set the password for each connection is because that The password can be changed in the safe Once a week at an unknown time so i must before get connection to get the new password and set it instead the exist.
the problem is that the Hikari keep the old password even if the pool empty and i give the new password
any idea how can i change the password for each get connection ?
this is the configuration file for Hikari
#maximum number of milliseconds that a client will wait for a connection
spring.datasource.connectionTimeout=20000
#minimum number of idle connections maintained by HikariCP in a connection pool
spring.datasource.minimumIdle=0
#maximum pool size
spring.datasource.maximumPoolSize=100
#maximum idle time for connection
spring.datasource.idleTimeout=30000
# maximum lifetime in milliseconds of a connection in the pool after it is closed.
spring.datasource.maxLifetime=0
#default auto-commit behavior.
spring.datasource.autocommit=true
spring.datasource.poolName=db2Pool
create the dataSource
@Bean("dataSourceMF")
@Order(PriorityOrdered.HIGHEST_PRECEDENCE)
public DataSource dataSourceMF() {
PasswordsMessage passwordsMessage = passwordApi.getPassword("username");
String userPassword = passwordsMessage.getPassword();
Properties configProps = new Properties();
configProps.put("poolName", poolName);
configProps.put("jdbcUrl", db2Url);
configProps.put("driverClassName", db2Driver);
configProps.put("username", db2User);
configProps.put("catalog", db2Catalog);
configProps.put("maximumPoolSize", maximumPoolSize);
configProps.put("minimumIdle", minimumIdle);
configProps.put("connectionTimeout", connectionTimeout);
configProps.put("idleTimeout", idleTimeout);
configProps.put("autoCommit", autoCommit);
configProps.put("dataSource.prepStmtCacheSize", 250);
configProps.put("dataSource.prepStmtCacheSqlLimit", 2048);
configProps.put("dataSource.cachePrepStmts", Boolean.TRUE);
configProps.put("dataSource.useServerPrepStmts", Boolean.TRUE);
configProps.put("password", userPassword);
HikariConfig hc = new HikariConfig(configProps);
dataSource = new HikariDataSource(hc);
return dataSource;
}
get connection
public Connection getConnection() throws SQLException, Exception {
PasswordsMessage passwordsMessage = passwordApi.getPassword("username");
String userPassword = passwordsMessage.getPassword();
try {
dataSource.setPassword(userPassword);
return dataSource.getConnection();
} catch (SQLException e) {
e.printStackTrace();
}
}
pom.xml
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.4.7</version>
</dependency>

