Click to See Complete Forum and Search --> : JDBC Driver Discovery?


bud1664
September 17th, 2004, 05:51 AM
Is their a way to discover all the JDBC drivers on the current classpath?

Currently I'm using:DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver() );
DriverManager.registerDriver( new com.mysql.jdbc.Driver() );//I think this is the correct line for MySQL, its remembered from memory so don't copy it & expect it to workEach in seperate try & catch blocks, so they all are given an attempted to be loaded.

Then using:List drivers = Collections.list( DriverManager.getDrivers() );
for( int i = 0; i < drivers.size(); i++ ) {
Driver driver = (Driver)drivers.get( i );
String name = driver.getClass().getName();
int majorVersion = driver.getMajorVersion();
int minorVersion = driver.getMinorVersion();
boolean isJdbcCompliant = driver.jdbcCompliant();
System.out.println( "Driver(" + i + "): " + name + ": v" + majorVersion + "." + minorVersion + " JDBC:" + isJdbcCompliant );
}To determin if a require Driver is loaded.

Cheers for any help, assistance or pointers.

cjard
September 17th, 2004, 07:40 AM
i wouldnt have thought so, because drivers arent self-registering.. if i asked you if there was a way to find all pictures on the hard drive.. what would you do? the pictures havent registered themselves anywhere, so there isnt a master list you can refer to..

as soon as you can answer the question of how to find every picture file, you will also know the answer of finding every database driver

bud1664
September 17th, 2004, 08:03 AM
I'ld search each & every directory for a specified pattern. I guess doing that kind of search in java might be problematic. You would have to do a cast to java.sql.driver for each class, and when casting exceptions don’t occur you have your driver to load.

It would be good if they were self-registering, just like Main-Class attribute in the Manifest file of jars. Maybe it would be a nice addition to the jar specification.

cjard
September 17th, 2004, 01:06 PM
I'ld search each & every directory for a specified pattern

what pattern?

*.gif? what about the JPEGs?
*.gif;*.jpg? what about the BMP.. and the.. and the...

and what about the obscure ones you never heard of..

this is a diverse byte-matching search.. what if there was an image file whose name didnt conform to a pattern.. or what if the file system you were using, had no patterns in the na,mes (like unix or amiga)..

you would have to inspect at a binary level, every file, to see if it was a known picture.. unless it loade ditself somewhere

and the same is true for jdbc drivers.

i'll give you an example of the opposite. fonts. fonts come in about 10 popular flavours, truetype and its shades, opentype and its shades, type one and its shades... there's loads though.. but, ona windows machine, to become usable.. a font must be entered into HKLM\software\microsoft\windowsnt\currentversion\fonts

so it is registered... and it is easy to get a list etc, of all the usable fonts..

no such analogue exists for java, and the classloaders are not equipped to interrogate a binary file to se eif it is a driver... so now that in-built searching does not exist, how do you search for your pictures/drivers? :)