I have a multi tenant application that tries to connect to database per tenant and each database will have its own username/password. I want to achieve this using a single datasource by switching between the datasources and users.
I tried to set the username and password at runtime on getting the connection.
Connection cnx = datasource.getConnection(username,password);
cnx.setCatalog(databaseName);
Unfortunately, the getconnection(username, password) is not implemented in HikariCP 3.1.0
Is there a way to achieve this. I know i can create the datasource per request and close it once the request is completed (not good solution). Also, I have more than 5000 tenants, so caching the datasource is not an option in my case.
Any help will be highly appreciated! Thanks in advance.
---Update--- I was able to set the user name/password at runtime, but not able to switch the database.