1

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.

Srik91
  • 79
  • 2
  • 12
  • Take a look at [this](https://fizzylogic.nl/2016/01/24/make-your-spring-boot-application-multi-tenant-aware-in-2-steps/). – LMC Apr 20 '19 at 04:06
  • It is again caching the datasources in memory. There is a limit on how many number of datasources you can cache depending on the number of open file descriptors. – Srik91 Apr 23 '19 at 20:56
  • Have you found a solution in the last year? – Yaytay Aug 17 '20 at 06:06

0 Answers0