JDK-6365188 : Auto-load JDBC drivers from META-INF/services
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.sql
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2005-12-19
  • Updated: 2011-02-16
  • Resolved: 2005-12-19
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
The need to explicitly load JDBC drivers using class.forName seems unnecessarilly messy.

JUSTIFICATION :
SInce JDBC was originally specified, the service directory has been invented for just such a purpose, loading whatever implentations are present. AFAIKS this is something which could easilly be retro-fitted without affecting existing code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
DriverManager.connect() could do a getResources() on the calling class' ClassLoader and load any drivers whose names are found in resources of the form "META-INF/services/java.sql.Driver". You'd probably want to do some caching here, maintaining a WeekHashMap of ClassLoaders on which this has already been done.

(My initial thought was to use the context ClassLoader but this would impinge on the security restriction in DriverManager, that it can only connect to classes accessible via the calling class' ClassLoader)

Normal practice would have only the drivers for the databases likely to be used on the ClassPath anyway. The only unnecessay one likely to be loaded would be the JDBC/ODBC Bridge.