aspose file tools*
The moose likes JDBC and the fly likes Driver loading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Driver loading " Watch "Driver loading " New topic
Author

Driver loading

tomasz brymora
Greenhorn

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:

jdbc.drivers=foo.bah.Driver:wombat.sql.Driver:bad.taste.ourDriver

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 "org.gjt.mm.mysql.Driver = 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: http://aspose.com/file-tools
 
subject: Driver loading
 
Similar Threads
The Class class
Driver wanted
DriverManager class
How do you connect jsp to Oracle?
Connect oracle databse from Websphere 6.1 with OS Authentication