• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can one Web Application connect to multiple databases

 
A Chauhan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,
I am working in an application that needs to connect with multiple databases .
Can someone tell me, is it possible to connect one web application (j2ee) with multiple databases.

thanks in advance
 
Rao Raghu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your web-application does not keep a track of how many databases you are connecting to. You can change the URL and database name in the getConnection() method and connect to as many dtabases as you want.
 
A Chauhan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply Raghu. But i want to know whether one web application
can connect to multiple databases simulteniously. If yes then please tell me how.
 
Rao Raghu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can write different methods which establish connection to different databases and return a connection object. Using Javabeans would be convenient here. You can call these methods as per your needs. But do close the statements and connections after each call.
 
Arulanand Dayalan
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you mean updating different datbases in same transaction. This can be done. You can use Java Transaction API(JTA) for doing this.

Hope this helps.

Thanks and Regards,
Arul.
 
Jan Cumps
Bartender
Posts: 2586
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can connect to as many databases as you like.
At the same time.

Regards, Jan
 
Niranjan Sarkar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can of course connect to different databases, just use different Connection objects for each connection that you establish.

As rightly said above use JTA, to manage your transaction. Best designs in real-time enterprise applications would of course stay clear of complicating matters with using single transactions for multiple databases.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic