ClassLoader and JNI issues

S

Steve Menard

I am having problems calling JDBC code from C/C++ via JNI.

I am embedding the JVM, and need access to any JDCB driver.

My problem is the following :

I can get the driver registered no problem, but when it comes time to
try and connect, the DriverManager "skips" over it because the driver's
ClassLoader is not the same as the caller's ClassLoader.

Now, I am calling this from C/C++ code, so there is no caller class, and
so no caller classloader.

I can make it work by bypassing th DriverManager completely, and asking
the driver to connect itself. That's fine as a stopgap solution, but I
would really like to fix this. The same problem occurs when I call
Class.forName(String), as this method looks at the caller's class and
classloader.

Is there a way to set or simulate a current class and/or classloader?

thanks in advance,

Steve
 
C

Chris Uppal

Steve said:
I can get the driver registered no problem, but when it comes time to
try and connect, the DriverManager "skips" over it because the driver's
ClassLoader is not the same as the caller's ClassLoader.

Now, I am calling this from C/C++ code, so there is no caller class, and
so no caller classloader.

The only thing /I/ can think of is to work around the problem with a bit of
"helper" Java code. That code just forwards to the actual methods you want to
invoke. So you call your helper code from JNI, rather than calling the "real"
methods directly.

I had to use a similar technique to workaround a buggy implementation of the
reflective methods in BEA JRockit implementation (presumably the problem was
related to the same issue).

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top