how to configure datasource in the springboot at runtime when database properties are received from UI with get request

Viewed 185

I have a requirement wherein a user enters database connection details like database type(oracle, mysql, hive), database url, driver name, user name, password through an UI and these connection details are passed to spring boot application as GET request URL params. then, from the spring boot application, I connect to the database, extract the data and send back to UI.

Users can enter any database connection information, hence these details are dynamic at a user level. how can I connect to databases dynamically during runtime with these user input details.

   GET Request: http://localhost:8080/api/getData
  
 the following database properties sent from UI to spring boot application      
 {
        dyType: 'hive',
    dbUrl:'jdbc:hive2://localhost:10000/default;principal=hive/localhostDU',
        driverClass: 'org.apache.hive.jdbc.HiveDriver',
        username: 'xyz',
        password: 'xxxxxxxx'
}

I want to set my datasource at runtime using above details.

0 Answers
Related