Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
311 views
in Technique[技术] by (71.8m points)

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

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.

question from:https://stackoverflow.com/questions/65921536/how-to-configure-datasource-in-the-springboot-at-runtime-when-database-propertie

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...