无法在Eclipse RCP IDE中连接MySQL [英] Cannot connect MySQL in Eclipse RCP IDE

查看:70
本文介绍了无法在Eclipse RCP IDE中连接MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部

当尝试使用Class.forName("com.mysql.jdbc.Driver")加载Driver类时,出现了com.mysql.jdbc.Driver异常.我已经编写了一个自定义Eclipse插件,并想访问我的自定义Eclipse插件中的数据库.

I am getting the com.mysql.jdbc.Driver exception when trying to load the Driver class using Class.forName("com.mysql.jdbc.Driver"). I have written a custom Eclipse plugin and wanted to access the database in my custom Eclipse plugin.

我尝试了以下2个选项,但两个选项显然都失败了:
1>将mysql连接JAR文件添加到Eclipse插件构建路径
2>将连接器JAR文件添加为库,并添加到插件的运行时类路径

I have tried following 2 options, both obviously failed:
1 > Adding the mysql connection JAR file to the Eclipse plugin build path
2 > Adding the connector JAR file as library and adding to the plugin's runtime classpath

有人可以帮我吗?

这是日志:

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)

推荐答案

我建议为MySQL驱动程序创建自己的OSGi捆绑包,请参见 http://wiki.eclipse.org/Create_and_Export_MySQL_JDBC_driver_bundle .然后,您必须在捆绑软件的plugin.xml中设置对创建的mysql-bundle的依赖.

I recommend to create your own OSGi-Bundle for the MySQL Driver, see http://wiki.eclipse.org/Create_and_Export_MySQL_JDBC_driver_bundle for a how-to. Afterwards you have to set a dependency in your plugin.xml of your bundle to the created mysql-bundle.

此外:请在OSGi环境中使用的不是DriverManager,而是数据源的实现.

In addition: Please use in an OSGi environment not the DriverManager but an implementation of DataSource.

这篇关于无法在Eclipse RCP IDE中连接MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆