首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用XQJ的简单查询

使用XQJ的简单查询
EN

Stack Overflow用户
提问于 2019-01-01 22:04:36
回答 1查看 400关注 0票数 0

前言: Oracle实现可能不是开源的。解决办法似乎是使用saxonica__。

如何导入OXQDataSource

Oracle使用:

import oracle.xml.xquery.OXQDataSource;

但这是从哪里来的呢?

我不知道要导入什么,也不知道JAR应该在XQJ示例7-1的类路径上从Oracle 文档中导入什么,因为我在尝试编译时获得了error: package oracle.xml.xquery does not exist

套餐java.lang.Object下的XQJ

编译错误,包不存在:

代码语言:javascript
复制
thufir@dur:~/NetBeansProjects/helloWorldBaseX$ 
thufir@dur:~/NetBeansProjects/helloWorldBaseX$ gradle clean run

> Task :compileJava FAILED
/home/thufir/NetBeansProjects/helloWorldBaseX/src/main/java/org/basex/examples/local/App.java:15: error: package oracle.xml.xquery does not exist
import oracle.xml.xquery.OXQDataSource;
                        ^
/home/thufir/NetBeansProjects/helloWorldBaseX/src/main/java/org/basex/examples/local/App.java:46: error: cannot find symbol
        OXQDataSource ds = new OXQDataSource();
        ^
  symbol:   class OXQDataSource
  location: class App
/home/thufir/NetBeansProjects/helloWorldBaseX/src/main/java/org/basex/examples/local/App.java:46: error: cannot find symbol
        OXQDataSource ds = new OXQDataSource();
                               ^
  symbol:   class OXQDataSource
  location: class App
3 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
2 actionable tasks: 2 executed
thufir@dur:~/NetBeansProjects/helloWorldBaseX$ 

带导入的代码:

代码语言:javascript
复制
package org.basex.examples.local;

import java.io.IOException;
import java.util.Properties;
import java.util.logging.Logger;
import javax.xml.xquery.XQConnection;
import javax.xml.xquery.XQException;
import javax.xml.xquery.XQPreparedExpression;
import javax.xml.xquery.XQSequence;
import org.basex.core.BaseXException;
import org.basex.core.Context;
import org.basex.core.cmd.CreateDB;
import org.basex.core.cmd.DropDB;
import org.basex.core.cmd.List;
import oracle.xml.xquery.OXQDataSource;

public final class App {

    private static final Logger LOG = Logger.getLogger(App.class.getName());
    private final Properties properties = new Properties();
    private final Context context = new Context();

    public static void main(String[] args) throws BaseXException, IOException {
        LOG.fine("starting..");
        new App().helloWorld();
    }

    private void list() throws BaseXException {
        LOG.info(new List().execute(context));
    }

    private void helloWorld() throws BaseXException, IOException {
        properties.loadFromXML(App.class.getResourceAsStream("/basex.xml"));
        String databaseName = properties.getProperty("databaseName");
        String databasePath = properties.getProperty("databasePath");

        list();
        new CreateDB(databaseName, databasePath).execute(context);
        list();
        new DropDB(databaseName).execute(context);
        list();

    }

    private void oracleXQJ() throws XQException {
        OXQDataSource ds = new OXQDataSource();
        XQConnection con = ds.getConnection();
        String query = "<hello-world>{1 + 1}</hello-world>";
        XQPreparedExpression expr = con.prepareExpression(query);
        XQSequence result = expr.executeQuery();
        // prints "<hello-world>2</hello-world>"
        System.out.println(result.getSequenceAsString(null));
        result.close();
        expr.close();
        con.close();
    }

}

我只是将导入语句放入其中以生成一个特定的错误。什么应该进口,从什么进口?

只有这一门课给出了问题,原因不明。不知道如何导入,也不知道如何为该导入在类路径上添加什么。

I 看见

代码语言:javascript
复制
The lib directory contains these JAR and ZIP files:

         classgen.jar
         jdev-rt.zip
         oraclexsql.jar
         transx.zip
         xml.jar
         xml2.jar
         xmldemo.jar
         xmlmesg.jar
         xmlparserv2.jar
         xschema.jar
         xsqlserializers.jar
         xsu12.jar

The jlib directory contains these JAR files:

         orai18n.jar
         orai18n-collation.jar
         orai18n-mapping.jar
         orai18n-utility.jar

其中之一,大概是OXQDataSource

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-02 00:22:55

XQJ的设计是从创建表示特定XQuery引擎和数据库的数据源开始,然后建立从应用程序到该数据源的连接,然后使用标准接口对数据源执行查询。原则上,如果要切换到不同的查询引擎,只需实例化不同的数据源即可。因此,如果您想从Oracle切换到Saxon,则实例化Saxon DataSource,而不是Oracle DataSource。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53999298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档