-2

i want to query existdb from Java. i know there are samples but where can i get the necessary packages to run the examples?

in the samples :

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;

where can i get these ? and what is the right standard connection string for exist-db? port number etc

and YES, i have tried to read the existdb documentation, but those are not really understandable for beginners. they are confusing. All i want to do is write a Java class in eclipse that can connect to a exist-db and query an xml document.

Sandra
  • 103
  • 2
  • 14

5 Answers5

2

Your question is badly written, and I think you are really not explaining what you are trying to do very well.

If you want the JAR files as dependencies directly for some project then you can download eXist and get them from there. Already covered several times here, which JAR files you need as dependencies is documented on the eXist website and links to that documentation have already been posted in this thread.

I wanted to add, that if you did want a series of simple Java examples that use Maven to resolve the dependencies (which takes away the hard work), then when we wrote the eXist book we provided just that in the Integration Chapter. It shows you how to use each of eXist's different APIs from Java for storing/querying/updating etc. You can find the code from that book chapter here: https://github.com/eXist-book/book-code/tree/master/chapters/integration. Included are the Maven project files to resolve all the dependencies and build and run the examples. If the code is not enough for you, you might also want to consider purchasing the book and reading the Integration Chapter carefully, that should answer all of your questions.

adamretter
  • 3,885
  • 2
  • 23
  • 43
1

i ended up with a maven project and imported some missing jars (like ws.commons etc) by manually installing them on maven. the missing jars i copied from the existdb installation path on my local system. then i got it to work.

Sandra
  • 103
  • 2
  • 14
  • That's also how I've done it here too. For anyone else interested: https://mvnrepository.com/artifact/org.apache.xmlrpc/xmlrpc-client and https://mvnrepository.com/artifact/commons-io/commons-io are availble on maven, "exist.jar" and "xmldb.jar" are available from eXist-db (when you download, or build form source). Those were the only libs needed to query a DB from tomcat/java (for me, so far...) – karljacuncha Aug 02 '17 at 16:32
0

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

There are several XML:DB examples provided in eXist's samples directory . To start an example, use the start.jar jar file and pass the name of the example class as the first parameter, for instance:

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

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();}
            }
        }
    }
}
CKuharski
  • 314
  • 3
  • 14
  • i have seen these examples, but where to get the packages? how set up and test these samples? – Sandra Feb 18 '15 at 15:25
  • Sandra - you can either 1) use maven 2) download database - http://sourceforge.net/projects/exist/files/Stable/2.2/ Then you should be able to start-up a database and connect to it mimicking the program above. – CKuharski Feb 18 '15 at 15:34
  • i do not work with a maven project. just want to create one simple java class. – Sandra Feb 18 '15 at 16:08
  • what would be the dependency to add for eXistdb? – Sandra Feb 18 '15 at 18:45
  • The dependencies are documented on http://exist-db.org/exist/apps/doc/deployment.xml#D2.2.6 – DiZzZz Feb 19 '15 at 11:57
0

On the page http://exist-db.org/exist/apps/doc/deployment.xml#D2.2.6 a list of dependencies is included; unfortunately there is no link to this page on http://exist-db.org/exist/apps/doc/devguide_xmldb.xml (should be added);

The latest xmldb.jar documentation can be found on http://xmldb.exist-db.org/

All the jar files can be retrieved by installing eXist-db from the installer jar; the files are all in EXIST_HOME/lib/core

DiZzZz
  • 621
  • 3
  • 12
-1

If you work with a maven project, try adding this to your pom.xml

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

Be aware that the release date is 2002.

Otherwise you can query exist-db via XML-RPC

ccheneson
  • 49,072
  • 8
  • 63
  • 68