aspose file tools*
The moose likes JDBC and the fly likes Can one Web Application connect to multiple databases Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Can one Web Application connect to multiple databases" Watch "Can one Web Application connect to multiple databases" New topic
Author

Can one Web Application connect to multiple databases

A Chauhan
Greenhorn

Joined: Nov 21, 2006
Posts: 15
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

Joined: Jan 05, 2007
Posts: 100
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.


RAGHU<br /> <br />"When the going gets tough, the tough get going"
A Chauhan
Greenhorn

Joined: Nov 21, 2006
Posts: 15
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

Joined: Jan 05, 2007
Posts: 100
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

Joined: Aug 10, 2005
Posts: 124
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

Joined: Dec 20, 2006
Posts: 2477
    
    7

You can connect to as many databases as you like.
At the same time.

Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
Niranjan Sarkar
Greenhorn

Joined: Jan 17, 2006
Posts: 5
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can one Web Application connect to multiple databases
 
Similar Threads
JDBC driver
JDBC
JPA/Hibernate: Selecting data from second database?
Max number of threads in a JVM
Configure Database dynamically in Hibernate