简体   繁体   中英

How to execute an AQL query with Java API?

I have a collection named docCollection and I want to perform a normal AQL query on for example:

FOR id IN docCollection FILTER id.center == "Germany" RETURN id

I have tried to use the example as stated here:

https://docs.arangodb.com/cookbook/JavaDriverXmlData.html

But it didn't worked for me and it showed me

Exception in thread "main" java.lang.NullPointerException

Normally you have to use driver.executeDocumentQuery(...) for document queries.

To illustrate the differences between driver.executeDocumentQuery(...) and driver.executeAqlQuery(...) I added an example .

Download the ArangoDB java driver on github and compile it with maven:

mvn clean install -DskipTests=true -Dgpg.skip=true -Dmaven.javadoc.skip=true -B

Maven creates the standalone driver JAR file (arangodb-java-driver-XXX-SNAPSHOT-standalone.jar) containing all dependencies in the target directory.

Fetch the example code:

 wget https://gist.githubusercontent.com/anonymous/bd68b523647548e5fb36d27c29561cfe/raw/f2922d431b9f1e5a3f3239e9024cf342536f55f7/AqlExample.java

Compile the example code:

 javac -classpath arangodb-java-driver-X.X.X-SNAPSHOT-standalone.jar AqlExample.java

Start the ArangoDB without authentication on the default port and run the example code:

 java -classpath arangodb-java-driver-X.X.X-SNAPSHOT-standalone.jar:. AqlExample

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM