Friday June 16, 2006
Mustang now packaged with Java DB
Mustang is now packaged with Java DB 10.2 aka Apache Derby, a pure java standards based database. This holds significance as Java DB implements all new features of JDBC 4.0 Specification. Among them are the Ease of Development and new JDBC driver loading mechanism to play with. This packaging will provide out of box database with a jdk release for the first time.
Go grab the bits of Mustang(b88) here and enjoy!
Posted at 08:52AM Jun 16, 2006 by amithanda in java |
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]