Eclipse plugin: Trying to load JDBC Driver via Class.forName("...")

Discussion in 'Java' started by georg.hartner@gmail.com, Jul 27, 2006.

  1. Guest

    Hi, I'm trying to write an eclipse plugin for Social Networks'
    Visualization. Therefore I need a Database Connection to an Oracle
    Database. I added the Driver JAR to the classpath and did all the other
    usual DB Connection stuff, but it always throws a
    ClassDefNotFoundException when I try to load the Driver via
    Class.ForName(...).

    Any solutions? (I guess its an easy question for people used to write
    eclipse plugins using external libraries ;) )

    Code (called out of a MultiPageEditor via Button ActionHandler - still
    a bit messed up, sorry ;) ):
    ------------------------------------------------
    public void generateData(Model md) {
    try {
    //DriverManager.registerDriver(new
    oracle.jdbc.driver.OracleDriver());
    Class.forName("oracle.jdbc.driver.OracleDriver");
    } catch (Exception e1) {
    e1.printStackTrace();
    }
    try {
    Connection conn =
    DriverManager.getConnection("jdbc:eek:racle:vcoeorad/vcoe",un,pw);
    ...........
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    --------------------------------------------------
    Exception:
    --------------------------------------------------
    java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
    at
    org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:407)
    at
    org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:352)
    at
    org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:83)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at util.DataImporter.generateData(DataImporter.java:40)
    at snv.ui.GeneratorComposite$1.mouseDown(GeneratorComposite.java:95)
    at
    org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:133)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
    at
    org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1914)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
    at
    org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:419)
    at
    org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at
    org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:95)
    at
    org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
    at
    org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92)
    at
    org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68)FEHLER
    BEIM LADEN DES TREIBERS!
    ---------------------------------------------

    Please help! :) Rescuer gets a beer when in Vienna!

    Gg
     
    , Jul 27, 2006
    #1
    1. Advertising

  2. Moiristo Guest

    wrote:
    > Code (called out of a MultiPageEditor via Button ActionHandler - still
    > a bit messed up, sorry ;) ):
    > ------------------------------------------------
    > public void generateData(Model md) {
    > try {
    > //DriverManager.registerDriver(new
    > oracle.jdbc.driver.OracleDriver());
    > Class.forName("oracle.jdbc.driver.OracleDriver");
    > } catch (Exception e1) {
    > e1.printStackTrace();
    > }



    The classname is alright, so it must mean that you've incorrectly set up
    the library. Be aware that you must add the jar itself to the classpath,
    not the directory containing it.
     
    Moiristo, Jul 27, 2006
    #2
    1. Advertising

  3. Guest


    >
    > The classname is alright, so it must mean that you've incorrectly set up
    > the library. Be aware that you must add the jar itself to the classpath,
    > not the directory containing it.


    Thanks for your immediate reply. I think i added it correctly (in the
    build path ("Add External JARs") as well as I hooked the checkbox for
    the export. I've often written programs using JDBC or orther external
    libraries. I think it's an eclipse specific issue corresponding to PDE
    or OSGi.

    I checked what you meant but it still doesn't work :(. Sorry. Next one?
    ;)
     
    , Jul 27, 2006
    #3
  4. Guest

    "SOLVED"! I think I found a suitable solution. I had to extract the jar
    file somewhere in the plugin directory and add the folder to the
    classpath through Manifest.MF - Runtime Configuration - Classpath -
    Add.

    Thanks
    G
     
    , Jul 27, 2006
    #4
    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. Betty
    Replies:
    1
    Views:
    9,928
    Juha Laiho
    May 21, 2005
  2. Bruce
    Replies:
    4
    Views:
    791
    Bjorn Abelli
    Mar 25, 2006
  3. Jimmy
    Replies:
    0
    Views:
    541
    Jimmy
    Mar 15, 2007
  4. Replies:
    1
    Views:
    766
  5. Lew
    Replies:
    0
    Views:
    550
Loading...

Share This Page