File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Application Frameworks and the fly likes Multi DataBase Connectivity with Spring and Jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Multi DataBase Connectivity with Spring and Jdbc" Watch "Multi DataBase Connectivity with Spring and Jdbc" New topic
Author

Multi DataBase Connectivity with Spring and Jdbc

Ishika
Greenhorn

Joined: Aug 07, 2008
Posts: 12
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 ]
Rajah Nagur
Ranch Hand

Joined: Nov 06, 2002
Posts: 239
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.


You can't wake a person who is <b><i>pretending</i></b> to be asleep.<br />Like what <b>"it"</b> does not like - <i> Gurdjieff </i>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multi DataBase Connectivity with Spring and Jdbc