使用rest在neo4j中运行cypher查询的java示例
试图构建一个用于访问neo4j数据的java客户端,我不想使用neo4j的嵌入式模式。请有人给我一个示例代码,我正在尝试运行以下代码使用rest在neo4j中运行cypher查询的java示例,java,neo4j,cypher,Java,Neo4j,Cypher,试图构建一个用于访问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.quer
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();
}
}
}
import org.neo4j.rest.graphdb.RestAPI;
导入org.neo4j.rest.graphdb.RestAPIFacade;
导入org.neo4j.rest.graphdb.RestGraphDatabase;
导入org.neo4j.rest.graphdb.query.RestCypherQueryEngine;
导入org.neo4j.rest.graphdb.util.QueryResult;
导入静态org.neo4j.helpers.collection.MapUtil.map;
导入java.util.Map;
公共类密码查询{
公共静态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(“开始n=node(2)返回n,n.name作为name;”,映射(“id”,0));
System.out.println(“已创建查询”);
用于(地图行:结果){
long id=((Number)row.get(“id”)).longValue();
System.out.println(“id为”+id);
}
}
捕获(例外e)
{
e、 printStackTrace();
}
}
}
但是它没有显示任何错误或异常,也没有生成任何输出。看起来像是一个打字错误,URL中有三个“t”
htttp://localhost:7474/db/data
此操作有效,您没有id结果列,也没有传入参数(建议使用参数)
公共类密码查询{
公共静态void main(字符串[]args){
试一试{
系统输出打印项次(“启动测试”);
最终RestAPI api=新的RestAPIFacade(“http://localhost:7474/db/data/");
System.out.println(“创建的API”);
最终RestCypherQueryEngine发动机=新RestCypherQueryEngine(api);
System.out.println(“引擎已创建”);
final QueryResult result=engine.query(“start n=node({id})返回id(n)作为id,n.name?作为name;”,map(“id”,2));
System.out.println(“已创建查询”);
用于(地图行:结果){
long id=((Number)row.get(“id”)).longValue();
System.out.println(“id为”+id);
}
}
捕获(例外e)
{
e、 printStackTrace();
}
}
}
没有问题,我故意这么做,因为stack over flow不允许http,所以这不是问题Hey Michael我不知道是什么问题仍然是同一个问题没有异常没有错误,我在eclipse中运行此代码,在同一系统中运行neo4j,是否存在依赖性问题??
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();
}
}
}