Accessing different database schemas using JNDI with Spring and Hibernate

Hi,

We are using Struts2+Spring+Hibernate+JNDI in our project. In our database we have tables in different schemas. At runtime, the DB schema must be selected dynamically depending on the user selection. How can I make Spring+JNDI pick up the right DB schema or datasource at runtime?
cuttieveenzAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
anilallewarConnect With a Mentor Commented:
The AbstractRoutingDataSource  is the concrete implementation of the methodology that I described above that is available in the Spring framework. You can find more details & example with Spring on the below sites.

http://blog.springsource.com/2007/01/23/dynamic-datasource-routing/
http://www.jdocs.com/spring/2.5.2/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.html
0
 
anilallewarCommented:
You can have a properties file that has mapping for schema - datasource name. This mapping can be picked up statically and your connection class can use the correspoding class to return the relevant connection.
0
 
anilallewarCommented:
Should be

your connection class can use the correspoding JNDI datasource to return the relevant connection from pool.
0
 
cuttieveenzAuthor Commented:
I have read something about the AbstractRoutingDataSource class. How is this used?
0
All Courses

From novice to tech pro — start learning today.