File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Driver loading 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 "Driver loading " Watch "Driver loading " New topic

Driver loading

tomasz brymora

Joined: May 31, 2004
Posts: 22
What are the pros/cons regarding loading a DB driver in a way that bypasses the usual way driver gets loaded (i.e. including location of the driver in the classpath, or physically placing it in the proper directory where the JVM expects drivers to live), and instead loading it dynamically.

I don't think it's a common way to deal with driver loading and it took me a while to find an example of how it's done. I did however, and now I'm wondering what are the implications of such a loading process.

The reason I've been isistant on using such a thing is that I want the app to completely self contained and as simple as possible.

Say the small desktop app works with the McKoi DB and its use is intened for people (single user most of the time) who maybe don't want to know about classpaths, JVM, directories and such in order to start the app. Instead, all they expect is to double click something and be done with it.

So what's good/bad about such approach?
Thank you in advance, Tomasz
Raj Chila
Ranch Hand

Joined: Mar 18, 2004
Posts: 128

hi tomasz,

I dont know if I understood your question correctly, but if you look at the DriverManager classes description, you could also specify a Driver in through a Property in a properties file that will be used at load time,

As part of its initialization, the DriverManager class will attempt to load the driver classes referenced in the "jdbc.drivers" system property. This allows a user to customize the JDBC Drivers used by their applications. For example in your ~/.hotjava/properties file you might specify:


When the method getConnection is called, the DriverManager will attempt to locate a suitable driver from amongst those loaded at initialization and those loaded explicitly using the same classloader as the current applet or application.

So you can still provide the "Double click" comfort to your clients, by providing a list of all the Databases that will be used from Developing to testing to production. worst is you can avoid "Class.forName" option and directly instantiate the driver class for example " = new Driver()", but this will "hard code" the Application with the MySQL database.

But thinking of the Driver loading, I think we need to some where do this loading as the dirver implementations are provided by the Database vendors.

Pros: you can keep the Application "database independent" all you need to do is specify a different driver class in your properties table.
I agree. Here's the link:
subject: Driver loading
It's not a secret anymore!