Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java neo4j QueryResult赢得';t出口_Java_Api_Neo4j - Fatal编程技术网

Java neo4j QueryResult赢得';t出口

Java neo4j QueryResult赢得';t出口,java,api,neo4j,Java,Api,Neo4j,目前我有这个班。当我删除QueryResult时,它运行main方法并自行完成。当我添加QueryResult时,我需要手动终止运行。我怎样才能使这一切优雅地结束?谢谢 public class TestConnect { public static void main(String[] args) { System.out.println("starting test"); final RestAPI api = new RestAPIFacade("http://loc

目前我有这个班。当我删除QueryResult时,它运行main方法并自行完成。当我添加QueryResult时,我需要手动终止运行。我怎样才能使这一切优雅地结束?谢谢

public class TestConnect {
  public static void main(String[] args) {
    System.out.println("starting test");
     final RestAPI api = new RestAPIFacade("http://localhost:7474/db/data");
    System.out.println("API created");
    final RestCypherQueryEngine engine = new RestCypherQueryEngine(api);
    System.out.println("engine created");
    QueryResult<Map<String,Object>> result = engine.query("start n=node({id}) return n;", map("id",0));
  }
}
公共类TestConnect{
公共静态void main(字符串[]args){
系统输出打印项次(“启动测试”);
最终RestAPI api=新的RestAPIFacade(“http://localhost:7474/db/data");
System.out.println(“创建的API”);
最终RestCypherQueryEngine发动机=新RestCypherQueryEngine(api);
System.out.println(“引擎已创建”);
QueryResult result=engine.query(“start n=node({id})返回n;”,map(“id”,0));
}
}
编辑:
我正在使用Java7

我没有使用neo4j的经验,但是QueryResults通常需要关闭,以便java释放/清理连接和类似的东西

顺便说一句,我不知道您使用的是哪个版本的java,但是如果是java 7或更高版本,并且这个结果实现了java.lang.AutoClosable(可能是这样),那么您可以使用自动资源管理!耶

因此,可以手动调用:
result.close
(最好在finally块中)或使用ARM:

try (QueryResult> result = engine.query("start n=node({id}) return n;", map("id",0))) { // Do stuff here } try(QueryResult>result=engine.query(“start n=node({id})return n;”,map(“id”,0))){ //在这里做事 }
可能应该这样做。

这样就可以了,但是这需要对象实现java.lang.autocloseable事实上,它是java.io.closeble的父对象,所以所有这些都可以。