Issue
I have a login page where I have to select which database it should connect
I have my configuration like this:
data-lang="js" data-hide="false" data-console="false" data-babel="false">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver" />
<property name="url" value="jdbc:db2://my_server:10000/DATABASE_1" />
<property name="username" value="galadm" />
<property name="password" value="galadm" />
</bean>
I using Spring JDBC Template Can I write something like this
<property name="url" value="jdbc:db2://my_server:50000/DATABASE{database_which_I_get_from_input}" />
I don't mind to have initial value i.e. DATABASE_1
Solution
Seems that the AbstractRoutingDataSource is a viable solution for you. Its the layer that acts as an intermediary between the multiple datasource, and determines which one to use dynamically.
The following blog solution describes how you can switch based on some attribute of the user’s context
https://spring.io/blog/2007/01/23/dynamic-datasource-routing/
Answered By - Master Slave
Answer Checked By - Terry (JavaFixing Volunteer)