wood burning stoves
The moose likes JDBC and Relational Databases and the fly likes Class.forName( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Class.forName("..");" Watch "Class.forName("..");" New topic


Pankaj Patro
Ranch Hand

Joined: Apr 20, 2005
Posts: 35

Can I connect to 2 different database server in a single JDBC application?

Or is it possible to call Class.forNmae("url1"); for a type 1 database server, then Class.forName("url2); for a type 2 databse server, in my JDBC application.

Thanks & Regards,
Pankaj Patro
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
You can connect to as many different databases as you need to. It doesn't matter of which type they are, and by which means you acquire them. Also, you can call the Class.forName() methods all before you make the connection.

By the way, a database server does not have a type, the JDBC driver for a database has a type.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Are you using a JDBC 2.0 driver? If so, obtain an InitialContext to obtain a DataSource by a JNDI lookup, and use the DataSource to get your Connection. You will need a DataSource for each DB.

SCJP 1.4, SCWCD 1.3, SCBCD 1.3
I agree. Here's the link: http://aspose.com/file-tools
subject: Class.forName("..");
It's not a secret anymore!