ClassLoader and JNI issues

Discussion in 'Java' started by Steve Menard, Jun 24, 2004.

  1. Steve Menard

    Steve Menard Guest

    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
     
    Steve Menard, Jun 24, 2004
    #1
    1. Advertising

  2. Steve Menard

    Chris Uppal Guest

    Steve Menard wrote:

    > 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
     
    Chris Uppal, Jun 25, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Hunsley

    IBM's JNI fails where Sun's JNI works

    Alex Hunsley, Nov 3, 2003, in forum: Java
    Replies:
    4
    Views:
    863
    Alex Hunsley
    Nov 4, 2003
  2. Pasturel Jean-Louis

    Porting JNI Windows under JNI LINUX + Wine ?

    Pasturel Jean-Louis, Feb 29, 2004, in forum: Java
    Replies:
    5
    Views:
    925
    Pasturel Jean-Louis
    Mar 3, 2004
  3. vasanth
    Replies:
    0
    Views:
    2,729
    vasanth
    Jan 25, 2005
  4. vasanth
    Replies:
    0
    Views:
    629
    vasanth
    Jan 25, 2005
  5. Berlin  Brown
    Replies:
    1
    Views:
    2,738
    Berlin Brown
    Sep 25, 2006
Loading...

Share This Page