sethu
sethu

Reputation: 8411

Using Spring to connect to a database that dynamically changes

I have seen many solutions which all make you first configure statically via XML the different datasources and then use AbstractRoutingDataSource to return back a key which you consume while defining the datasource.

As here: dynamic datasource routing

But my case is different. I dont know how many databases there could be in my web application. I am building an app where each user uploads a small h2 db dump from a desktop app. The web app will download the h2 db dump and then connect to it.

So to make things simple to understand. Each user will have his/her own database file that I need to connect to once the user logs in. Since the number of users are not fixed, I dont know how many databases I will need to connect to, hence I cannot statically configure them in an XML file.

How to go about doing this in Spring? Also, not sure if it helps, these h2 dbs are read only. I am not going to write to them.

This is my configuration.

Maven, Spring MVC, JOOQ, H2 DBs

Upvotes: 4

Views: 1186

Answers (1)

Myo
Myo

Reputation: 72

If you like to change the database changes dynamically, you have to write the UI for database source information and set to the spring config files in version-4.0.

Upvotes: -1

Related Questions