Monday February 20, 2006
JDBC Driver Loading with Mustang
We have simplified the way to get a JDBC connection from Mustang. This is part of the Ease of Development features for which we laid the foundation in Tiger and are being built into the java platform.
So what has changed ?
Pre Mustang, to get a JDBC connection, in stand alone mode, we do
Class.forName("com.myorg.jdbc.jdbcDriverImpl");
Connection con = DriverManager.getConnection(url, user, pass);
Post Mustang, to get a JDBC connection, in stand alone mode, it is
If a JDBC driver is packaged as a service, you can simply say
// commented Class.forName() below
//Class.forName("com.myorg.jdbc.jdbcDriverImpl");Connection con = DriverManager.getConnection(url, user, pass);
What is meant by JDBC driver being packaged as a service ?
The Service Provider mechanism is defined according the the JAR Specification. So JDBC driver vendors need to packages their drivers as a service. The DriverManager code will look for implementations of java.sql.Driver in classpath and do Class.forName() implicitly.
How does it help a developer ?
(1) Less clutter in code.
(2) The developer no longer needs to know the class which implements java.sql.Driver interface from the JDBC driver jar.
Can the developer simply ignore calling Class.forName() from Mustang ?
No, they can't. If your JDBC driver vendor supplies the driver exposing it as a service, only and only then, you can ignore calling Class.forName(). Else the semantics remain same as they were with pre JDBC 4.0.
Will the existing applications still run with this change ?
Yes, very much. This change ensures backward compatibility i.e. applications which get ported to Mustang will still run. New applications can be written to reduce clutter in the code. The idea is to move away from explicitly doing a Class.forName() and that eventually all driver vendors package their JDBC drivers exposed as a service.
How will things change in the Java EE world ?
Nothing changes in the Java EE world. This driver loading is primarily for non managed scenario or stand alone applications. The way you get a connection from a DataSource stays as it is.
What's the advantage to the driver vendor ?
One advantage from driver vendor's perspective is that the vendor can change the name of the class which implements java.sql.Driver interface without worrying too much about a developer's application. But that's a long way to go, after this gets adopted as the default way in stand alone applications to get a JDBC connection.
All these changes(see Lance Andersen's blog, Spec Lead JDBC 4.0) are being done as part of JDBC 4.0 which is being delivered as part of Mustang. I will write more on some of the other features soon...
Posted at 01:46PM Feb 20, 2006 by amithanda in java | Comments[10]
Posted by A. Sundararajan on February 20, 2006 at 04:18 PM IST #
Posted by jothir on February 21, 2006 at 09:18 AM IST #
Posted by sankara on February 21, 2006 at 11:42 AM IST #
Posted by Shreyas on February 21, 2006 at 12:00 PM IST #
Posted by Amit Handa on February 21, 2006 at 12:20 PM IST #
Posted by Amit Handa on February 21, 2006 at 12:22 PM IST #
Posted by Amit Handa on February 21, 2006 at 02:03 PM IST #
Posted by Surendra Prasad on February 22, 2006 at 04:29 PM IST #
Posted by alex on February 24, 2006 at 02:07 AM IST #
Posted by Amit Handa on February 25, 2006 at 11:07 AM IST #