Name: krT82822 Date: 01/12/2000
java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, symcjit)
DriverManager does not load the 3rd party jdbc drivers if they are installed as
extensions or application classes when called from C++ using JNI methods. The
same program works when the jdbc odbc drivers are used.
Steps:
======
In the main() method of a C++ program:
a) create the java vm with -Djava.class.path option set to the directory
containing 3rd party jdbc driver, say weblogic.
b) find the web logic driver class using env->FindClass() method
c) find the java.sql.DriverManager class and the getConnection() method.
d) Call the method to create the connection using url, username and password.
The above steps do not work with weblogic whereas they work with jdbc odbc
bridge driver class and the appropriate URL.
Using the log writer in DriverManager.java, displays a message
"skipping: weblogic.jdbc.mssqlserver4.Driver"
Solution attempted:
===================
When calling from C++, there is no classloader. Hence, the DriverManager native
method getCallerClassLoader() returns null. Since the weblogic driver is in the
application classpath, it cannot be loaded using no classloader.
By changing the DriverManager.getCallerClass() method to use the system
classloader if getCallerClassLoader() returned null fixed the problem.
********************************************************************************
private static Class getCallerClass(ClassLoader callerClassLoader,
String driverClassName) {
Class callerC = null;
try {
if ( callerClassLoader == null ) {
callerC = Class.forName(driverClassName, true,
ClassLoader.getSystemClassLoader);
}
else {
callerC = Class.forName(driverClassName, true, callerClassLoader);
}
catch (Exception ex) {
callerC = null; // being very careful
}
return callerC;
}
********************************************************************************
Please suggest any workarounds or if this has been fixed.
(Review ID: 99650)
======================================================================