我已经阅读了问题UcanAccess intro,但无法使驱动程序在OSGi / RCP应用程序中工作。我认为这是一个类加载器问题,但不知道如何解决。
相关代码段,它在第二行失败。 MDB存在,使用UcanAccess的非OSGi Java应用程序可以成功打开它。
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con = DriverManager.getConnection("jdbc:ucanaccess://" + FILENAME);
我得到以下异常:
**4302 INFO org.eclipse.ecf.osgi.services.remoteserviceadmin - [S:{org.osgi.framework.hooks.service.EventListenerHook}={service.id=274, service.bundleid=86, service.scope=singleton}] ServiceEvent REGISTERED
net.ucanaccess.jdbc.UcanaccessSQLException: user lacks privilege or object not found java.lang.ClassNotFoundException: net.ucanaccess.converters.Functions cannot be found by org.hsqldb.hsqldb_2.3.1 net.ucanaccess.converters.Functions in statement [CREATE FUNCTION SLN(par0 DOUBLE,par1 DOUBLE,par2 DOUBLE) RETURNS DOUBLE LANGUAGE JAVA DETERMINISTIC NO SQL EXTERNAL NAME 'CLASSPATH:net.ucanaccess.converters.Functions.sln']
at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:247)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at com.easa.motordb.load.HornerLoad.execute(HornerLoad.java:26)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:294)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:247)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:229)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:149)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:499)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:825)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:701)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$6(HandledContributionItem.java:685)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:613)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4353)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4172)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3761)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at com.easa.acmotor.base.Application.start(Application.java:24)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found java.lang.ClassNotFoundException: net.ucanaccess.converters.Functions cannot be found by org.hsqldb.hsqldb_2.3.1 net.ucanaccess.converters.Functions in statement [CREATE FUNCTION SLN(par0 DOUBLE,par1 DOUBLE,par2 DOUBLE) RETURNS DOUBLE LANGUAGE JAVA DETERMINISTIC NO SQL EXTERNAL NAME 'CLASSPATH:net.ucanaccess.converters.Functions.sln']
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.executeUpdate(Unknown Source)
at net.ucanaccess.converters.LoadJet.exec(LoadJet.java:1258)
at net.ucanaccess.converters.LoadJet.access$0(LoadJet.java:1253)
at net.ucanaccess.converters.LoadJet$FunctionsLoader.createFunctions(LoadJet.java:156)
at net.ucanaccess.converters.LoadJet$FunctionsLoader.addFunctions(LoadJet.java:151)
at net.ucanaccess.converters.LoadJet$FunctionsLoader.loadMappedFunctions(LoadJet.java:178)
at net.ucanaccess.converters.LoadJet$FunctionsLoader.access$2(LoadJet.java:177)
at net.ucanaccess.converters.LoadJet.loadDB(LoadJet.java:1310)
at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:236)
... 48 more
Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found java.lang.ClassNotFoundException: net.ucanaccess.converters.Functions cannot be found by org.hsqldb.hsqldb_2.3.1 net.ucanaccess.converters.Functions
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.Routine.getMethods(Unknown Source)
at org.hsqldb.Routine.getMethod(Unknown Source)
at org.hsqldb.Routine.resolveReferences(Unknown Source)
at org.hsqldb.Routine.resolve(Unknown Source)
at org.hsqldb.StatementSchema.getResult(Unknown Source)
at org.hsqldb.StatementSchema.execute(Unknown Source)
at org.hsqldb.Session.executeCompiledStatement(Unknown Source)
at org.hsqldb.Session.executeDirectStatement(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 58 more
Caused by: java.lang.ClassNotFoundException: net.ucanaccess.converters.Functions cannot be found by org.hsqldb.hsqldb_2.3.1
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:432)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:345)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:337)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
... 67 more
我已采取的步骤:
从ucanaccess创建一个插件/捆绑
Require-Bundle:清单中的org.hsqldb.hsqldb; bundle-version =“ 2.3.1”
使它成为注册伙伴(Eclipse-BuddyPolicy:已注册)
使我的捆绑软件知道(Eclipse-RegisterBuddy:ucanaccess)
确保所有捆绑包均已自动启动(ucanaccess,hsql和我的捆绑包)
最佳答案
我最初仅在新捆绑包中包含ucanaccess.jar文件,并将其他jar文件放在目标平台/插件列表中。
解决方案是使用所有UcanAccess所需的jar文件(ucanaccess-2.0.9.4.jar,commons-lang-2.6.jar,commons-logging-1.1.1.jar,hsqldb.jar,jackcess-2.0.8)创建新的捆绑包。 。罐)。
关于java - 在OSGI中使用ucanaccess时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29595659/