关于JavaDriver连接Neo4j中的关系查询
各位大佬您们好,用JavaDriver连接Neo4j后,再实现两个节点之间的关系查询时,以下这段代码会报错,查阅了网上许多资料还是没有找到解决的办法,希望各位大佬能够指点以下!感谢! 以下是我的错误行代码。请问能不能解决这个将关系类型转换成路径的问题 `console.log('public static void getPathsInfo(String cypher){ getDriver();
int count = 0;
try(Session session = driver.session()){
//result包含了所有的path
StatementResult result = session.run(cypher);
System.out.println(result.toString());
while(result.hasNext()){
Record record = result.next();
List<Value> value = record.values();
for(Value i:value){
** //这一步出现了问题,显示的是: Cannot coerce RELATIONSHIP to Path**
*Path path = i.asPath();*
//处理路径中的关系
Iterator<Relationship> relationships = path.relationships().iterator();
//Iterator<Node> nodes = path.nodes().iterator();//得到path中的节点
while(relationships.hasNext()){
count++;
Relationship relationship = relationships.next();
long startNodeId = relationship.startNodeId();
long endNodeId = relationship.endNodeId();
String relType = relationship.type();
System.out.println("关系"+count+": ");
System.out.println("关系类型:"+relType);
System.out.println("from "+startNodeId+"-----"+"to "+endNodeId);
System.out.println("关系属性如下:");
//得到关系属性的健
Iterator<String> relKeys = relationship.keys().iterator();
//这里处理关系属性
while(relKeys.hasNext()){
String relKey = relKeys.next();
String relValue = relationship.get(relKey).asObject().toString();
System.out.println(relKey+"-----"+relValue);
}
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
}
}
}
close();
}')