当前位置: 首页 > 知识库问答 >
问题:

OSGI礼宾中的JDBC Oracle

魏烨熠
2023-03-14

我需要一些关于如何使用ojdbc8(我尝试使用ojdbc6,ojdbc7也从未工作过)作为OSGi包进行部署的线索,我可以使用class.load()加载类,但是在运行时会出现以下错误:

java.net.MalformedURLException: unknown protocol: bundle
    at java.net.URL.<init>(URL.java:421)
    at java.net.URL.<init>(URL.java:310)
    at java.net.URL.<init>(URL.java:333)
    at org.eclipse.concierge.BundleImpl$Revision.createURL(BundleImpl.java:2460)
    at org.eclipse.concierge.BundleImpl$JarBundleRevision.findFile(BundleImpl.java:3633)
    at org.eclipse.concierge.BundleImpl$JarBundleRevision.lookupFile(BundleImpl.java:3587)
    at org.eclipse.concierge.BundleImpl$Revision$BundleClassLoader.findOwnResources(BundleImpl.java:3220)
    at org.eclipse.concierge.BundleImpl$Revision$BundleClassLoader.findResource1(BundleImpl.java:2747)
    at org.eclipse.concierge.BundleImpl$Revision$BundleClassLoader.findResource0(BundleImpl.java:2685)
    at org.eclipse.concierge.BundleImpl$Revision$BundleClassLoader.findResource(BundleImpl.java:2541)
    at org.eclipse.concierge.BundleImpl$Revision$BundleClassLoader.getResource(BundleImpl.java:2517)
    at java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:1307)
    at java.lang.Class.getResourceAsStream(Class.java:2223)
    at oracle.jdbc.driver.SQLStateMapping.doGetMappings(SQLStateMapping.java:208)
    at oracle.jdbc.driver.SQLStateMapping.getMappings(SQLStateMapping.java:194)
    at oracle.jdbc.driver.DatabaseError.<clinit>(DatabaseError.java:1075)
    at oracle.jdbc.driver.OracleDiagnosabilityMBean.getDescription(OracleDiagnosabilityMBean.java:96)
    at javax.management.StandardMBean.getMBeanInfo(StandardMBean.java:456)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getNewMBeanClassName(DefaultMBeanServerInterceptor.java:333)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:319)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
    at oracle.jdbc.driver.OracleDriver.registerMBeans(OracleDriver.java:409)
    at oracle.jdbc.driver.OracleDriver$1.run(OracleDriver.java:241)
    at java.security.AccessController.doPrivileged(Native Method)
    at oracle.jdbc.driver.OracleDriver.<clinit>(OracleDriver.java:237)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at java.sql.DriverManager.isDriverAllowed(DriverManager.java:556)
    at java.sql.DriverManager.getConnection(DriverManager.java:661)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at nz.co.spark.cg.shared.sql.SQLUtils.getDBConnection(SQLUtils.java:19)
    at nz.co.spark.cg.shared.sql.SQLUtils.createLocalDB(SQLUtils.java:29)
    at nz.co.spark.cg.extractor.task.ChatExtractorJob.<init>(ChatExtractorJob.java:61)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at org.quartz.simpl.SimpleJobFactory.newJob(SimpleJobFactory.java:56)
    at org.quartz.simpl.PropertySettingJobFactory.newJob(PropertySettingJobFactory.java:69)
    at org.quartz.core.JobRunShell.initialize(JobRunShell.java:127)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:375)
java.net.MalformedURLException: unknown protocol: bundle
    at java.net.URL.<init>(URL.java:421)
    at java.net.URL.<init>(URL.java:310)
    at java.net.URL.<init>(URL.java:333)
    at org.eclipse.concierge.BundleImpl$Revision.createURL(BundleImpl.java:2460)
    at org.eclipse.concierge.BundleImpl$JarBundleRevision.findFile(BundleImpl.java:3633)
    at org.eclipse.concierge.BundleImpl$JarBundleRevision.lookupFile(BundleImpl.java:3587)
    at org.eclipse.concierge.BundleImpl$Revision$BundleClassLoader.findOwnResources(BundleImpl.java:3220)
    at org.eclipse.concierge.BundleImpl$Revision$BundleClassLoader.findResource1(BundleImpl.java:2747)
    at org.eclipse.concierge.BundleImpl$Revision$BundleClassLoader.findResource0(BundleImpl.java:2685)
    at org.eclipse.concierge.BundleImpl$Revision$BundleClassLoader.findResource(BundleImpl.java:2541)
    at org.eclipse.concierge.BundleImpl$Revision$BundleClassLoader.getResource(BundleImpl.java:2517)
    at java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:1307)
    at java.util.ResourceBundle$Control$1.run(ResourceBundle.java:2686)
    at java.util.ResourceBundle$Control$1.run(ResourceBundle.java:2671)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.util.ResourceBundle$Control.newBundle(ResourceBundle.java:2670)
    at java.util.ResourceBundle.loadBundle(ResourceBundle.java:1510)
    at java.util.ResourceBundle.findBundle(ResourceBundle.java:1474)
    at java.util.ResourceBundle.findBundle(ResourceBundle.java:1428)
    at java.util.ResourceBundle.findBundle(ResourceBundle.java:1428)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1370)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:782)
    at oracle.jdbc.driver.Message11.msg(Message11.java:36)
    at oracle.jdbc.driver.DatabaseError.findMessage(DatabaseError.java:939)
    at oracle.jdbc.driver.OracleDiagnosabilityMBean.getDescription(OracleDiagnosabilityMBean.java:96)
    at javax.management.StandardMBean.getMBeanInfo(StandardMBean.java:456)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getNewMBeanClassName(DefaultMBeanServerInterceptor.java:333)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:319)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
    at oracle.jdbc.driver.OracleDriver.registerMBeans(OracleDriver.java:409)
    at oracle.jdbc.driver.OracleDriver$1.run(OracleDriver.java:241)
    at java.security.AccessController.doPrivileged(Native Method)
    at oracle.jdbc.driver.OracleDriver.<clinit>(OracleDriver.java:237)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at java.sql.DriverManager.isDriverAllowed(DriverManager.java:556)
    at java.sql.DriverManager.getConnection(DriverManager.java:661)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at nz.co.spark.cg.shared.sql.SQLUtils.getDBConnection(SQLUtils.java:19)
    at nz.co.spark.cg.shared.sql.SQLUtils.createLocalDB(SQLUtils.java:29)
    at nz.co.spark.cg.extractor.task.ChatExtractorJob.<init>(ChatExtractorJob.java:61)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at org.quartz.simpl.SimpleJobFactory.newJob(SimpleJobFactory.java:56)
    at org.quartz.simpl.PropertySettingJobFactory.newJob(PropertySettingJobFactory.java:69)
    at org.quartz.core.JobRunShell.initialize(JobRunShell.java:127)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:375)
java.net.MalformedURLException: unknown protocol: bundle
    at java.net.URL.<init>(URL.java:421)
    at java.net.URL.<init>(URL.java:310)
    at java.net.URL.<init>(URL.java:333)
    at org.eclipse.concierge.BundleImpl$Revision.createURL(BundleImpl.java:2460)
    at org.eclipse.concierge.BundleImpl$JarBundleRevision.findFile(BundleImpl.java:3633)
    at org.eclipse.concierge.BundleImpl$JarBundleRevision.lookupFile(BundleImpl.java:3587)
    at org.eclipse.concierge.BundleImpl$Revision$BundleClassLoader.findOwnResources(BundleImpl.java:3220)
    at org.eclipse.concierge.BundleImpl$Revision$BundleClassLoader.findResource1(BundleImpl.java:2747)
    at org.eclipse.concierge.BundleImpl$Revision$BundleClassLoader.findResource0(BundleImpl.java:2685)
    at org.eclipse.concierge.BundleImpl$Revision$BundleClassLoader.findResource(BundleImpl.java:2541)
    at org.eclipse.concierge.BundleImpl$Revision$BundleClassLoader.getResource(BundleImpl.java:2517)
    at java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:1307)
    at java.lang.Class.getResourceAsStream(Class.java:2223)
    at oracle.jdbc.driver.OracleDriver.<clinit>(OracleDriver.java:323)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at java.sql.DriverManager.isDriverAllowed(DriverManager.java:556)
    at java.sql.DriverManager.getConnection(DriverManager.java:661)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at nz.co.spark.cg.shared.sql.SQLUtils.getDBConnection(SQLUtils.java:19)
    at nz.co.spark.cg.shared.sql.SQLUtils.createLocalDB(SQLUtils.java:29)
    at nz.co.spark.cg.extractor.task.ChatExtractorJob.<init>(ChatExtractorJob.java:61)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at org.quartz.simpl.SimpleJobFactory.newJob(SimpleJobFactory.java:56)
    at org.quartz.simpl.PropertySettingJobFactory.newJob(PropertySettingJobFactory.java:69)
    at org.quartz.core.JobRunShell.initialize(JobRunShell.java:127)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:375)

这发生在oracle jdbc驱动程序中,在SQLStateMapping类中,classr试图使用SQLStateMapping.class.GetResourceStream(“error..xml”)获取资源文件;

发生这种情况是因为在OSGi包中,它会更改URL并在其上插入“bundle”单词,并且资源永远不会正确返回,抛出java.net.MalFormeDurlException。有人知道怎么解决这个问题吗?

共有1个答案

卫琛
2023-03-14

如果您想在OSGi中使用JDBC,我建议您使用(PAX-JDBC)。它制作了从JDBC驱动程序注册DataSourceFactory所需的所有胶水,如果您正在使用ConfigAdmin服务,您也可以注册DataSource-s。当我使用一个能够处理JDBC连接或数据源的库时,我从OSGi服务中获取实例并使用它。它的好处你也可以使用连接池,PAX-JDBC支持它。如果文档不清楚,我可以用一些例子扩展这个答案,但对于开始有一个很好的教程。它基于karaf,但可以在任何标准OSGi实现中进行调整。

 类似资料:
  •  游戏信息 H5游戏:http://f2e.duowan.com/s/lib/mobile/gamesInfo.js APP游戏:http://f2e.duowan.com/s/lib/mobile/h5gamesInfo.js

  • 问题内容: 是否可以在OSGi应用程序中使用非osgi库? 例如,我正在开发一个基于语义的搜索引擎,并且正在为其使用第三方自然语言处理库(http://wiki.opencog.org/w/RelEx_Dependency_Relationship_Extractor)。 是否可以在OSGi应用程序中连接不支持OSGi(作为几个jar文件)的库? 问题答案: 如先前答案中所写,如果要在包中使用其他

  • 注意:我刚刚发现了这个问题,但它是针对更老版本的POI的。但显然这是一个持续的问题。

  • NowCoder 题目描述 在一个 m*n 的棋盘的每一个格都放有一个礼物,每个礼物都有一定价值(大于 0)。从左上角开始拿礼物,每次向右或向下移动一格,直到右下角结束。给定一个棋盘,求拿到礼物的最大价值。例如,对于如下棋盘 // 1 10 3 8 12 2 9 6 5 7 4 11 3 7 16 5 礼物的最大价值为 1+12

  • 我的应用程序有一些OSGI模块和一个非OSGI部分。我尝试通过ApacheAries的JNDI在非osgi子系统中查找osgi服务。我用玻璃鱼。 我的蓝图xml如下所示: 我尝试了以下查找: 我部署了4个捆绑包: Apache Aries Util 但我得到一个例外: 我忘带包裹了吗?有人能帮我吗?

  • 主要内容:面试的基本礼仪1,面试的基本礼仪2,面试的基本礼仪3,面试的基本礼仪4,面试的基本礼仪5,面试的基本礼仪6,面试的基本礼仪7,面试的基本礼仪8,面试的基本礼仪9,面试的基本礼仪10,面试的基本礼仪11,面试的基本礼仪12,面试的基本礼仪13,面试的基本礼仪14,面试的基本礼仪15面试的基本礼仪15篇 面试的基本礼仪1   电话面试礼仪:   可视电话屏幕面试正日益普遍,因为很多公司想通过屏幕进行面试,避免舟车之旅,从而降低招聘开支。运用可视电话面试,招聘者可以很快就淘汰大部分人选而决定