Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute an AQL query with Java API?

Tags:

java

arangodb

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

like image 537
Haseb Ansari Avatar asked Sep 24 '26 22:09

Haseb Ansari


1 Answers

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
like image 159
Achim Brandt Avatar answered Sep 27 '26 11:09

Achim Brandt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!