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.
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.
- duplicates
-
JDK-6290312 Feature request to add JDBC 4.0(JSR 221) to J2SE 6.0
- Closed