Class.forName("..");

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

Rancher

Posts: 42972

73

posted 11 years ago

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

Posts: 1683

posted 11 years ago

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.