2011-02-01 68 views
1

所有,不能在Eclipse RCP IDE

試圖加載使用Class.forName("com.mysql.jdbc.Driver")驅動程序類時,我收到com.mysql.jdbc.Driver異常連接MySQL。我編寫了一個自定義Eclipse插件,並希望訪問我的自定義Eclipse插件中的數據庫。

我曾嘗試以下2個選項,這兩個明顯的失敗:
1>添加MySQL連接JAR文件的Eclipse插件構建路徑
2>添加連接器JAR文件庫,並增加了插件的運行時類路徑

任何人都可以請幫我一下嗎?

這裏是日誌:

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) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Unknown Source) 
    at draft1.set1.utility.DatabaseUpdatesUtility.commitPerspectiveToDB(DatabaseUpdatesUtility.java:48) 
    at draft1.set1.display.DomainEditor.doSaveAs(DomainEditor.java:57) 
    at org.eclipse.ui.internal.SaveAsAction.run(SaveAsAction.java:64) 
    at org.eclipse.jface.action.Action.runWithEvent(Action.java:498) 
    at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584) 
    at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501) 
    at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411) 
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) 
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053) 
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066) 
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657) 
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640) 
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604) 
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438) 
    at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671) 
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) 
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664) 
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) 
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115) 
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) 
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) 
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) 
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369) 
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619) 
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574) 
    at org.eclipse.equinox.launcher.Main.run(Main.java:1407) 
    at org.eclipse.equinox.launcher.Main.main(Main.java:1383) 
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/mysql 
    at java.sql.DriverManager.getConnection(Unknown Source) 
    at java.sql.DriverManager.getConnection(Unknown Source) 
    at draft1.set1.utility.DatabaseUpdatesUtility.commitPerspectiveToDB(DatabaseUpdatesUtility.java:53) 
    at draft1.set1.display.DomainEditor.doSaveAs(DomainEditor.java:57) 
    at org.eclipse.ui.internal.SaveAsAction.run(SaveAsAction.java:64) 
    at org.eclipse.jface.action.Action.runWithEvent(Action.java:498) 
    at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584) 
    at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501) 
    at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411) 
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) 
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053) 
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066) 
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657) 
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640) 
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604) 
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438) 
    at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671) 
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) 
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664) 
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) 
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115) 
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) 
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) 
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) 
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369) 
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619) 
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574) 
    at org.eclipse.equinox.launcher.Main.run(Main.java:1407) 
    at org.eclipse.equinox.launcher.Main.main(Main.java:1383) 
+0

「com.mysql.jdbc.Driver異常」並不意味着什麼。什麼是你得到的實際例外?請編輯您的文章並添加完整的堆棧跟蹤。 – 2011-02-01 22:25:46

回答

1

我建議創建自己的OSGi的捆綁的MySQL驅動程序,請參見http://wiki.eclipse.org/Create_and_Export_MySQL_JDBC_driver_bundle的-如何。之後,您必須在您的bundle的plugin.xml中將dependency設置爲已創建的mysql-bundle。

另外:請在OSGi環境中使用,不是DriverManager,而是DataSource的實現。