1

trying to build a java client for accessing the neo4j data , I don't want to use embedded mode of Neo4j please somebody give me the example code for the same am trying to run following code

    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(); 

         }
         }
       }

But it is not showing any error or exception and it is not producing any output.

2 Answers 2

1

Looks like a typo, you have three "t" in the URL htttp://localhost:7474/db/data

Sign up to request clarification or add additional context in comments.

1 Comment

no Problem in that, i have done intentionally coz stack over flow was not allowing the http so thats not the problem
1

This works, you didn't have an id result column and were also not passing in a parameter (which is recommended, using parameters)

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();

     }
     }
   }

1 Comment

hey Michael I dont know whats the problem still same problem no exception no error,am running this code in eclipse and running the neo4j in same system , is there any dependency problem ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.