Haseb Ansari
Haseb Ansari

Reputation: 607

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://github.com/arangodb/docs/blob/2f0a96c23630719e09f1b7af6aaf106c44332555/drivers/java-examples-xml-data.md

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

Exception in thread "main" java.lang.NullPointerException

Upvotes: 3

Views: 1447

Answers (1)

Achim Brandt
Achim Brandt

Reputation: 211

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-X.X.X-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

Upvotes: 5

Related Questions