Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1200
  • Last Modified:

Accessing different database schemas using JNDI with Spring and Hibernate


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?
  • 3
1 Solution
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.
Should be

your connection class can use the correspoding JNDI datasource to return the relevant connection from pool.
cuttieveenzAuthor Commented:
I have read something about the AbstractRoutingDataSource class. How is this used?
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now