1

I have three environments i.e. DEV, TEST and PROD. so three databases

I want to update data from any environment to any enviroment only in a particular table.

e.g. suppose I want to update TABLE1 data in PROD database, I have to select the enviroment from a drop down and click "save" in DEV or TEST.

To implement it I need new datasource object and then I need to fire a query to update/insert the data in that perticular enviroment.

Here I have two ways to do it: 1. Explicity fetch my database.properties and get all the configurations and create datasource and fire the query using simple JDBC connection. 2. Use Spring framework, configure it's application context and get it from there and run the configured query.

My application is in Spring2 and for database mapping, i am using iBatis.

I want to know the best way to implement it and tutorial which can help me in implementing it. I searched for it but got confused.

user1653773
  • 373
  • 1
  • 5
  • 18

1 Answers1

1

Looks like this is for you: AbstractRoutingDataSource.

Here is some discussion: How to programatically change databases in Spring with one DataSource?

Community
  • 1
  • 1
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • I don't want to change the application datasource. I need a new datasource object which can be created dynamically (as per environment selected by user i.e. TEST/DEV/PROD) and use that datasource to fire a query which is configure in my iBATIS SQL MAP file. and then destroy that datasource. – user1653773 Mar 24 '14 at 12:17
  • What's problem to encapsulate `create/destroy` logic within that `AbstractRoutingDataSource` implementation ? – Artem Bilan Mar 24 '14 at 12:19