简体   繁体   English

如何使用Java API执行AQL查询?

[英]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: 我有一个名为docCollection的集合,我想执行一个正常的AQL查询,例如:

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 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 线程“main”java.lang.NullPointerException中的异常

Normally you have to use driver.executeDocumentQuery(...) for document queries. 通常,您必须使用driver.executeDocumentQuery(...)进行文档查询。

To illustrate the differences between driver.executeDocumentQuery(...) and driver.executeAqlQuery(...) I added an example . 为了说明driver.executeDocumentQuery(...)driver.executeAqlQuery(...)之间的差异,我添加了一个示例

Download the ArangoDB java driver on github and compile it with maven: 在github上下载ArangoDB java驱动程序并使用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. Maven创建包含目标目录中所有依赖项的独立驱动程序JAR文件(arangodb-java-driver-XXX-SNAPSHOT-standalone.jar)。

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: 在默认端口上启动ArangoDB而不进行身份验证并运行示例代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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