如何使用apache-camel连接到oracle数据库?

时间:2016-05-25 14:18:26

标签: java maven apache-camel apache-karaf

目前我正在从属性文件中读取端点。我想从DB中获取它们。我已经编写了一个单独的java文件来连接到DB,但karaf会抛出异常。

我也在pom.xml中添加了包

Export-Package:oracle.jdbc,oracle.jdbc.driver

Import-Package:!javax。*,!oracle。**

    // Reading endpoints from property file
    String endPoint1 = propInfo.hashprops.get("endpoint1");
    String endPoint2 = propInfo.hashprops.get("endpoint2");
    from(endPoint1)
    .doTry()
    .setHeader(userid, constant("abcd"))
    .setHeader(password, constant("abcd"))
    .to(endPoint2)
    .doCatch(ConnectException.class)
    .process(new Processor(){
        public void process(Exchange ex) throws Exception {
            ex.getIn().setBody("Exception "));
        }
    })
    .doCatch(Exception.class)
    .process(new Processor(){
        public void process(Exchange ex) throws Exception {
            ex.getIn().setBody("Exception "));
        }
    });

如果我尝试从DB中读取它

   DbConnect obj = new DbConnect();
    String endPoint1 = obj.getEndpoint("endpoint1");
    String endPoint2 = obj.getEndpoint("endpoint2");
    from(endPoint1)
    .doTry()
    .setHeader(userid, constant("abcd"))
    .setHeader(password, constant("abcd"))
    .to(endPoint2)
    .doCatch(ConnectException.class)
    .process(new Processor(){
        public void process(Exchange ex) throws Exception {
            ex.getIn().setBody("Exception "));
        }
    })
    .doCatch(Exception.class)
    .process(new Processor(){
        public void process(Exchange ex) throws Exception {
            ex.getIn().setBody("Exception "));
        }
    });
  

java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver not not   发现者是com.app.routes [246]

1 个答案:

答案 0 :(得分:3)

您必须将oracle数据库驱动程序包装到osgi包中:
install -s wrap:file:///LOCAL_PATH/ojdbc6.jarinstall -s wrap:mvn:com.oracle/ojdbc6/11.2.0.2.0

通过控制台检查包装的驱动程序包是否已加载并启动。

使用数据库连接将oracle依赖项添加到您的bundle:

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.2.0</version>
        <scope>provided</scope>
    </dependency>

现在导入所需的包:

Import-Package : oracle.jdbc, oracle.jdbc.driver, oracle.jdbc.pool

希望这有帮助!