Add JDBC Database Connection to an Eclipse Plug-in

When you add JDBC database connection to an Eclipse plug-in, you may get the following error message:

Error message(partial):
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)

You may check again and again if the JDBC library has already added to the build path. That will not work, because JDBC library needs to be added as a dependency to make it work.

You need create your own plug-in(an osgi bundle) for the MySQL Driver by following steps below:

1. New -> Plug-in from Existing JAR archives
2. Add external jars
3. Complete using default settings

Afterwards you have to add it as a dependency in your plug-in.

Now it is working!

Category >> Rich Client Platform(RCP)  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
<pre><code> 
String foo = "bar";
</code></pre>
  • Will

    Never mind, just figured it out. I moved the .jar file to the META-INF directory and also added it to MANIFEST.MF -> Runtime -> Classpath

  • Will

    Did you ever figure out this problem? I’m having the same issue

  • Ivoss

    Hi,
    this seems to be the only post I have found that is related to what I am trying to do. I am creating an Eclipse plugin where I would need to connect to DB. No matter how I am trying I keep getting the ClassNotFound Exception.

    Unfortunately, even after following your steps I am getting the same error :/ I have added the project created from jar file under dependencies, required plugins but it still doesn’t work.

    Any thoughts? Do you have any working example for any DB?

    Many thanks,
    Ivoss

  • nitish

    hi,
    i am create a bundel name mysqlConectorPlug but i got following exception

    org.osgi.framework.BundleException: The bundle “de.vogella.rap.first_1.0.0.qualifier [56]” could not be resolved. Reason: Missing Constraint: Require-Bundle: mysqlConectorPlug; bundle-version=”1.0.0″
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1332)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolutionFailureException(AbstractBundle.java:1316)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:323)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
    at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)