Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Java查询existdb_Java_Exist Db - Fatal编程技术网

从Java查询existdb

从Java查询existdb,java,exist-db,Java,Exist Db,我想从Java查询existdb。我知道有一些示例,但在哪里可以获得运行示例所需的包 在样本中: import javax.xml.transform.OutputKeys; import org.exist.storage.serializers.EXistOutputKeys; import org.exist.xmldb.EXistResource; import org.xmldb.api.DatabaseManager; import org.xmldb.api.base.Collec

我想从Java查询existdb。我知道有一些示例,但在哪里可以获得运行示例所需的包

在样本中:

import javax.xml.transform.OutputKeys;
import org.exist.storage.serializers.EXistOutputKeys;
import org.exist.xmldb.EXistResource;
import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Collection;
import org.xmldb.api.base.Database;
import org.xmldb.api.modules.XMLResource;
我在哪里可以买到这些? exist db的正确标准连接字符串是什么?端口号等

是的,我试着阅读了existdb文档,但是对于初学者来说,这些文档并不能真正理解。它们令人困惑。
我所要做的就是在eclipse中编写一个Java类,该类可以连接到现有数据库并查询xml文档。

如果您使用maven项目,请尝试将其添加到pom.xml中

<dependency>
    <groupId>xmldb</groupId>
    <artifactId>xmldb-api</artifactId>
    <version>20021118</version>
</dependency>

XML数据库
现在是2002年

否则,您可以通过XML-RPC从以下位置查询exist db:

eXist的示例中提供了几个XML:DB示例 目录要开始一个示例,请使用start.jar文件并传递 示例类的名称作为第一个参数,例如:

java-jar start.jar org.exist.examples.xmldb.Retrieve[-other 选项]

在页面上包含依赖项列表;遗憾的是,上没有指向此页面的链接(应添加)

最新的xmldb.jar文档可以在


从安装程序jar安装eXist db可以检索所有jar文件;文件都在
EXIST\u HOME/lib/core

你的问题写得很糟糕,我认为你没有很好地解释你想要做的事情

如果您希望JAR文件直接作为某个项目的依赖项,那么您可以下载eXist并从那里获取它们。这里已经讨论了好几次了,作为依赖项所需的JAR文件在eXist网站上有文档记录,并且该文档的链接已经发布在这个线程中

我想补充一点,如果您确实想要一系列使用Maven来解决依赖关系的简单Java示例(这就省去了大量的工作),那么当我们编写时,我们只在集成一章中提供了这些。它向您展示了如何使用eXist不同于Java的API来存储/查询/更新等。您可以在这里找到该书章节中的代码:。包括Maven项目文件,用于解析所有依赖项并构建和运行示例。
如果代码不适合你,你可能还想考虑购买书和仔细阅读集成章节,这应该回答你的所有问题。

< P>我结束了一个Maven项目,并通过手工安装Maven,导入了一些缺省的jar(如W.Calson等)。 我从本地系统上的existdb安装路径复制的丢失JAR。
然后我让它开始工作。

这是exist db,它没有任何文档吗?我已经删除了我最后的评论。我已经看到了这些例子,但是从哪里可以得到这些软件包呢?如何设置和测试这些示例?Sandra-你可以1)使用maven 2)下载数据库-然后你应该能够启动一个数据库并模仿上面的程序连接到它。我不使用maven项目。只想创建一个简单的java类。eXistdb要添加的依赖项是什么?这些依赖项记录在eXistdb要添加的依赖项上?这个依赖项太旧了,请不要使用it@DiZzZz:正如我在评论中补充的,它的发布日期是2002年,指出它很旧。这也是我在这里做的。对于其他感兴趣的人:并且可以在maven上使用,“exist.jar”和“xmldb.jar”可以从existDB获得(当您下载或构建表单源代码时)。这些是从tomcat/java查询DB所需的唯一LIB(对我来说,到目前为止…)
Example: Retrieving a Document with XML:DB
import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import org.xmldb.api.*;
import javax.xml.transform.OutputKeys;
import org.exist.xmldb.EXistResource;

public class RetrieveExample {

    private static String URI = "xmldb:exist://localhost:8080/exist/xmlrpc";

    /**
     * args[0] Should be the name of the collection to access
     * args[1] Should be the name of the resource to read from the collection
     */
    public static void main(String args[]) throws Exception {

        final String driver = "org.exist.xmldb.DatabaseImpl";

        // initialize database driver
        Class cl = Class.forName(driver);
        Database database = (Database) cl.newInstance();
        database.setProperty("create-database", "true");
        DatabaseManager.registerDatabase(database);

        Collection col = null;
        XMLResource res = null;
        try {    
            // get the collection
            col = DatabaseManager.getCollection(URI + args[0]);
            col.setProperty(OutputKeys.INDENT, "no");
            res = (XMLResource)col.getResource(args[1]);

            if(res == null) {
                System.out.println("document not found!");
            } else {
                System.out.println(res.getContent());
            }
        } finally {
            //dont forget to clean up!

            if(res != null) {
                try { ((EXistResource)res).freeResources(); } catch(XMLDBException xe) {xe.printStackTrace();}
            }

            if(col != null) {
                try { col.close(); } catch(XMLDBException xe) {xe.printStackTrace();}
            }
        }
    }
}