• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

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.
 
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!