从Java查询exists-db

时间:2015-02-18 15:07:14

标签: 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.Collection;
import org.xmldb.api.base.Database;
import org.xmldb.api.modules.XMLResource;

我在哪里可以得到这些? 什么是exists-db的正确标准连接字符串?端口号等

和YES,我试图阅读existsdb文档,但对于初学者来说这些并不是真的可以理解。他们很困惑。 我想做的就是在eclipse中编写一个Java类,它可以连接到exists-db并查询xml文档。

5 个答案:

答案 0 :(得分:2)

你的问题写得不好,我认为你真的没有解释你想要做的很好。

如果您希望JAR文件直接作为某个项目的依赖项,那么您可以下载eXist并从那里获取它们。这里已经多次介绍过,eXist网站上记录了您需要哪些JAR文件作为依赖项,并且已经在此主题中发布了该文档的链接。

我想补充一点,如果你确实想要一系列使用Maven来解析依赖关系的简单Java示例(这会带来艰苦的工作),那么当我们编写eXist book时,我们只提供了集成章节。它向您展示了如何使用来自Java的每个eXist不同的API来存储/查询/更新等。您可以在此处找到该书章节中的代码:https://github.com/eXist-book/book-code/tree/master/chapters/integration。包括用于解析所有依赖项以及构建和运行示例的Maven项目文件。 如果代码对您来说还不够,您可能还需要考虑购买本书并仔细阅读集成章节,这应该回答您的所有问题。

答案 1 :(得分:1)

我最终得到了一个maven项目并通过在maven上手动安装它们来导入一些丢失的罐子(如ws.commons等)。 我从本地系统上的existdb安装路径复制的丢失的jar。 然后我开始工作了。

答案 2 :(得分:0)

来自:http://exist-db.org/exist/apps/doc/devguide_xmldb.xml

  

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

     

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

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

答案 3 :(得分:0)

在页面http://exist-db.org/exist/apps/doc/deployment.xml#D2.2.6上包含依赖项列表;很遗憾,http://exist-db.org/exist/apps/doc/devguide_xmldb.xml上没有此页面的链接(应添加);

最新的xmldb.jar文档可在http://xmldb.exist-db.org/

上找到

可以通过从安装程序jar安装eXist-db来检索所有jar文件;这些文件都在EXIST_HOME/lib/core

答案 4 :(得分:-1)

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

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

请注意release date是2002。

否则,您可以通过XML-RPC

查询exists-db
相关问题