my dog learned polymorphism*
The moose likes Struts and the fly likes Change DB runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Change DB runtime" Watch "Change DB runtime" New topic
Author

Change DB runtime

Krishnakumar Ramanathan
Greenhorn

Joined: Aug 04, 2008
Posts: 6
Hi all,
this is my code in applicationcontext.xml and its working fine, my doubt is how to change the DB at run time, In our application we have 4 -5 Databases and user is allowed to change the Db once he/she login

<bean id="placeholderConfigurer"
class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="location" value="classpath:ryanco.properties"/>
<property name="ignoreUnresolvablePlaceholders" value="true"></property>
</bean>

<!-- ========================= DataSource ========================= -->

<!-- DataSource Definition -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>${db.driverClassName}</value>
</property>
<property name="url">
<value>${db.1.url}</value>
</property>
<property name="username">
<value>${db.1.username}</value>
</property>
<property name="password">
<value>${db.1.password}</value>
</property>
</bean>


this is the code in properties file

db.1.name=Database3
db.1.password=test
db.1.username=test
db.1.driverClassName=oracle.jdbc.driver.OracleDriver
db.1.url=jdbc\ Oracle\:thin\:@10.10.4.3\:1521\ Database3

thanks in advance
[ October 02, 2008: Message edited by: Krishnakumar Ramanathan ]
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Is there a particular error that you are running across or are you not sure where to start on solving this problem?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Looks like you are using Spring Framework, so better post this in Application Framework section.

Cant help you much cause I don't know Spring !


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Change DB runtime
 
Similar Threads
how to add dditional properties to DB url in Spring ?
[Spring] Exception while creating the session factory
Spring Javamelody
BasicDataSource reconnect issue.
Spring - Connection Problem in some Unit Tests