This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes EJB and other Java EE Technologies and the fly likes Dynamically connection to multiple databases from single J2ee Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Dynamically connection to multiple databases from single J2ee Application" Watch "Dynamically connection to multiple databases from single J2ee Application" New topic
Author

Dynamically connection to multiple databases from single J2ee Application

Sudheesh
Greenhorn

Joined: Sep 22, 2005
Posts: 11
Dear sirs,

I have a J2ee application which is running in JBOSS Server. The Data tier is MySql. We are using CMP
Now the scenario is like this,
We are having two clients, and the clients have different sub users. The clients are using two seperate database for the same application. Now the application is working in two different servers assigned for each clients. Now we are planning to integrate it to a single application . I would like to know whether
1. Is it possible to specify the JNDI names for more than one database in the deployement descriptor?
2. if it is then, how can we instruct the container to lookup dynamically for the appropriate database based on the user logged in to the application .
I am planning to setup a new DB for the users information sothat the container can select the appropriate DB based on the user logged in...

Thankyou,
Sudheesh K S,
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30356
    
150

Sudheesh,
You can't have the same CMP point to different databases at the same time. Why not deploy the application twice and have each user point to a different one?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
deepak jawa
Greenhorn

Joined: Jun 03, 2006
Posts: 3
I am facing this problem now and have a solution for this...

same CMP class can be used but deployed with different ejb-name/jndi-name/datasource

so if u have 2 clients to support, the class remains same, but the deployment descriptors deploy the same CMP with 2 different names, 2 diff JNDI.. & they have different datasources...
Now in your code, u have the client info, which can be used to lookup the appropriate JNDI name.. (the jndi-name has a prefix of client name, which can be used during lookup..)

If you can write the DD by hand, well & gud.. because none of existing EJB doclet probably support such feature... i wud be writing a doclet for my code soon, as the number of CMPs is 100+ ..

I would like to have more suggestions on same from experts..

-thnx
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Dynamically connection to multiple databases from single J2ee Application