gpt4 book ai didi

java - 使用XQJ进行简单查询

转载 作者:行者123 更新时间:2023-12-02 10:25:15 27 4
gpt4 key购买 nike

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

如何导入OXQDataSource

Oracle 使用:

导入oracle.xml.xquery.OXQDataSource;

但这从何而来?

我不明白要导入什么,也不明白 XQJ 示例 7-1 的类路径上应该包含什么 JAR甲骨文docs因为我在尝试编译时收到错误:package oracle.xml.xquery不存在

package对于 java.lang.Object 下的 XQJ

编译错误,包不存在:

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$

导入代码:

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();
}

}

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

由于未知的原因,只有这一类出现了问题。不知道如何导入,也不知道要在classpath上放什么用于该导入。

<小时/>

see :

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

最佳答案

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

关于java - 使用XQJ进行简单查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53999298/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com