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(
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(
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:
String foo = "bar";
  • 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

    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,

  • nitish

    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(
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolutionFailureException(
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(
    at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(
    at org.eclipse.osgi.framework.eventmgr.EventManager$