SK.
SK.

Reputation: 1510

Spring MVC: Set property value based on input

I have a login page where I have to select which database it should connect enter image description here

I have my configuration like this:

	<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

Upvotes: 0

Views: 223

Answers (1)

Master Slave
Master Slave

Reputation: 28569

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/

Upvotes: 1

Related Questions