[英]java example of running cypher queries in neo4j using rest
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 试图建立一个Java客户端来访问neo4j数据,我不想使用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();
}
}
}
But it is not showing any error or exception and it is not producing any output. 但是它没有显示任何错误或异常,也没有产生任何输出。
看起来像是一个错字,URL htttp://localhost:7474/db/data
有三个“ t”
This works, you didn't have an id result column and were also not passing in a parameter (which is recommended, using parameters) 此方法有效,您没有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();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.