在 osgi 中使用 ucanaccess 时出错
Posted
技术标签:
【中文标题】在 osgi 中使用 ucanaccess 时出错【英文标题】:error using ucanaccess in osgi 【发布时间】:2015-04-12 23:01:18 【问题描述】:我已阅读问题UcanAccess intro,但无法让驱动程序在 OSGi / RCP 应用程序中工作。我认为这是一个类加载器问题,但不知道如何解决。
相关的sn-p代码,第二行就失败了。 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 和我的包)
【问题讨论】:
【参考方案1】:我最初只在新包中包含了 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.jar)。
【讨论】:
【参考方案2】:您忽略了在 getConnection 中为数据库用户名和密码放置空的 ""。试试这个代码:
con = DriverManager.getConnection("jdbc:ucanaccess://" + FILENAME, "", "");
【讨论】:
感谢您的建议,但同样的错误 con = DriverManager.getConnection("jdbc:ucanaccess://" + FILENAME, "", "");【参考方案3】:您的问题现在可能已经解决了,但是对于那些可以使用另一个提示的人:放下线路。
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
它对我来说非常有用。我使用 JDK 1.8 和 Jackcess 2.08 真的
【讨论】:
以上是关于在 osgi 中使用 ucanaccess 时出错的主要内容,如果未能解决你的问题,请参考以下文章
jdo/OSGi:捆绑更新后构建 JDO PersistenceManagerFactory 时出错
使用 UCanAccess 保存数据时 Java 应用程序挂起