Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Multi DataBase Connectivity with Spring and Jdbc

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!!
Can any one help me to configure multiple database using spring and jdbc.

Problem Statement:
My application needs to have functionality of year wise login.So for that I have 3 datasources db0607, db0708, db0809 and by default it points to db0809. I thought of using AbstractRoutingDataSource.
However,I recognized a problem.I would switch to a Datasource say db0708, and then navigate around and realize that i am back at the default db0809. I can't seem to figure out how to fix this.How would i go about fixing this?

This is how my Code goes



Dao Code:


application-data.xml code :

<bean name="employeeDao" class="com.testdb.testeg.persistance.EmployeeDaoImpl">
<property name="dataSource">
<ref bean="dataSource">
</property>
</bean>

<bean id="parentDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
abstract="true">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url">
<value>jdbc:racle:thin:@localhost:1521:XE</value>
</property>
</bean>

<bean id="dataSource0809" parent="parentDataSource">
<property name="username" value="${db.0809.username}"></property>
<property name="password" value="${db.0809.password}"></property>

</bean>


<bean id="dataSource0708" parent="parentDataSource">
<property name="username" value="${db.0708.username}"></property>
<property name="password" value="${db.0708.password}"></property>
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="WEB-INF/db.properties"/>
</bean>

<bean id="dataSource" class="com.testdb.testeg.web.LoginRoutingDataSource">
<property name="targetDataSources">
<map >
<entry key="com.testdb.testeg.web.LoginType.login0708" value-ref="dataSource0708"/>
<entry key="com.testdb.testeg.web.LoginType.login0809" value-ref="dataSource0809"/>
</map>
</property>
<property name="defaultTargetDataSource" ref="dataSource0809"/>
</bean>


Thanks in Advance,
Java Ranch User
[ August 11, 2008: Message edited by: dev Cats ]
 
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is hard to read. Please use Code Tag (For details: refer Ranch FAQ section). Also remove commented sections and system outs.

Edit and repost.
 
Men call me Jim. Women look past me to this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic