How to create Dynamic connections (datasource) in spring using JDBC

10,634

Take a look at Spring's AbstractRoutingDataSource ( javadoc-api ). Which allows you to maintain a "router" dataSource bean that would be able to route to a required real dataSource at runtime based on a single property provided ( in your case it would be a server id ).

Here is more about AbstractRoutingDataSource: Dynamic DataSource Routing

Share:
10,634

Related videos on Youtube

jaya
Author by

jaya

Updated on June 05, 2022

Comments

  • jaya
    jaya about 2 years

    I have a a spring application where i need to get server details for a oracle table and create dynamic connections as and when require based on some server id, How can I make this work?

  • jaya
    jaya almost 13 years
    Thanks for the reply, in this example he is using property file for getting the datasource details, In my case i want that to be dynamic,the server details should come up for database.
  • tolitius
    tolitius almost 13 years
    @jaya, can you give a bit more details about what it is you are trying to do, and why a property file approach would not work for you. As usually you know all the databases you work with in advance ( connection details to which you can list in property file[s] ). /litius
  • Andreas Wederbrand
    Andreas Wederbrand over 12 years
    I found this question on a quest of my own to do a similar thing and I can answer the question from my perspective. I need to be able to create data sources on the fly using values found in permanent database. The number of data sources can vary and new ones can be added on the fly.