This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Multiple Drivers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Multiple Drivers" Watch "Multiple Drivers" New topic

Multiple Drivers

Jim Robinson

Joined: Jan 30, 2001
Posts: 3
I have been assigned a project in which I am to connect using 3 different drivers for 3 different databases. For this assignment, I've built a GUI with a JCombo box. When a choice is made from the combo box, a properties file is chosen, the driver is loaded and registered, and metadata is obtained from the database.
The 3 databases are MSAccess, MySQL, and Pointbase (from the Core Java book by Horstmann). When I choose from the combo box, the first choice works fine. It doesn't matter which database/driver combination I choose, they all work as long as it is the FIRST choice. Any subsequent choices from the combo box result in an SQLException (no suitable driver).
My question is: Do I have to close the connection and make a new connection to load another driver? If so, how do I test for an open connection and close the currently open one?
Do I have to un-register drivers before registering a new one? And is this true even if each connection is a new, distinct object (a separate connection object for each database). I tried making a separate connection object for each database depending on the combo box choice, but I received the same SQLException (no suitable driver).

Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
As to your question... the answer is no.
Are you doing a Class.forName() for each driver? Show us some code because this should not be a problem.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Jim Robinson

Joined: Jan 30, 2001
Posts: 3
You were right. Using Class.forName() instead of trying to set the system property solved the problem. Thanks!

[This message has been edited by Jim Robinson (edited March 17, 2001).]

Joined: Jul 20, 2001
Posts: 1
hey Jim Robinson
can u provide me the souce code of the 3-DATABASE Connection.
i'm having same proj. but i facing probs.ur code will help me a lot. thanks
Jim Robinson

Joined: Jan 30, 2001
Posts: 3
// Make a Connection and create Statement and DatabaseMetaData objects
public void getDatabaseInformation(String fileName){

try {
con = getConnection(fileName);
stmt = con.createStatement();
md = con.getMetaData();
catch(SQLException e) {
while(e != null) {
System.out.println("Error closing connection in tab switch");
System.out.println("SQLState: " + e.getSQLState());
System.out.println("Message: " + e.getMessage());
System.out.println("Vendor Code: " + e.getErrorCode());
e = e.getNextException();
catch(IOException e) {
System.out.println("Error in I/O operation: " + e);

// Makes the connection to the database
public static Connection getConnection(String fileName) throws SQLException, IOException {
Properties props = new Properties();
FileInputStream in = new FileInputStream(fileName);

// force the driver to load with Class.forName()
try {
catch(ClassNotFoundException e){
System.out.println("Exception loading driver: " + e);

String url = props.getProperty("jdbc.url");
String username = props.getProperty("jdbc.username");
String password = props.getProperty("jdbc.password");
return DriverManager.getConnection(url);
I agree. Here's the link:
subject: Multiple Drivers
It's not a secret anymore!