1

试图构建一个用于访问 Neo4j 数据的 Java 客户端,我不想使用 Neo4j 的嵌入式模式,请有人给我相同的示例代码,我正在尝试运行以下代码

    import org.neo4j.rest.graphdb.RestAPI;
    import org.neo4j.rest.graphdb.RestAPIFacade;
    import org.neo4j.rest.graphdb.RestGraphDatabase;
    import org.neo4j.rest.graphdb.query.RestCypherQueryEngine;
    import org.neo4j.rest.graphdb.util.QueryResult;
    import static org.neo4j.helpers.collection.MapUtil.map;
    import java.util.Map;


    public class CypherQuery {
         public static void main(String[] args) {
             try{
          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");
         final QueryResult<Map<String,Object>> result = engine.query("start n=node(2) return n, n.name as name;", map("id", 0));

         System.out.println("query created");
         for (Map<String, Object> row : result) {
            long id=((Number)row.get("id")).longValue();
            System.out.println("id is " + id);
         }
         }
         catch(Exception e)
         {
            e.printStackTrace(); 

         }
         }
       }

但它没有显示任何错误或异常,也没有产生任何输出。

4

2 回答 2

1

看起来像是错字,您的网址中有三个“t”htttp://localhost:7474/db/data

于 2013-04-25T09:46:07.007 回答
1

这行得通,您没有 id 结果列,也没有传入参数(建议使用参数)

public class CypherQuery {
     public static void main(String[] args) {
         try{
      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");
     final QueryResult<Map<String,Object>> result = engine.query("start n=node({id}) return id(n) as id, n.name? as name;", map("id", 2));

     System.out.println("query created");
     for (Map<String, Object> row : result) {
        long id=((Number)row.get("id")).longValue();
        System.out.println("id is " + id);
     }
     }
     catch(Exception e)
     {
        e.printStackTrace();

     }
     }
   }
于 2013-05-07T16:10:48.617 回答