使用orientdb打印到java控制台的最短路径

使用orientdb打印到java控制台的最短路径,orientdb,shortest-path,Orientdb,Shortest Path,我想在Java控制台中打印两个顶点之间的最短路径。我不能打印任何东西,如果您有任何方法,我将不胜感激 String subquery = "Select shortestpath(17:10, 17:14, BOTH) "; Iterable<OrientVertex> result = orientDBGraph.command(new OSQLSynchQuery<OrientVertex>(subquery)).execute(); Assert.assertTru

我想在Java控制台中打印两个顶点之间的最短路径。我不能打印任何东西,如果您有任何方法,我将不胜感激

String subquery = "Select shortestpath(17:10, 17:14, BOTH) ";
Iterable<OrientVertex> result = orientDBGraph.command(new OSQLSynchQuery<OrientVertex>(subquery)).execute();
Assert.assertTrue(result.iterator().hasNext());
System.out.println(result);

for (OrientVertex d : result) {
  System.out.println("Shortest path from " + ((OrientVertex) d.getProperty("$current")).getProperty("name") + " and "
    + ((Iterable<OrientVertex>) d.getProperty("$target")).iterator().next().getProperty("name") + " is: "
    + d.getProperty("path"));
}
String子查询=“选择最短路径(17:10,17:14,两者)”;
Iterable result=orientDBGraph.command(新OSQLSynchQuery(子查询)).execute();
Assert.assertTrue(result.iterator().hasNext());
系统输出打印项次(结果);
对于(定向顶点d:结果){
System.out.println(“从“+((OrientVertex)d.getProperty($current”)).getProperty(“name”)+”和
+((Iterable)d.getProperty(“$target”)).iterator().next().getProperty(“name”)+“是:”
+d.getProperty(“路径”);
}

代码:

import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;

public class test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        String dbName = "ytrewa";

        OrientGraphFactory dbfactory = new OrientGraphFactory("remote:127.0.0.1:2424/"+dbName, "root", "root").setupPool(1, 50);

        OrientGraph g = dbfactory.getTx();

        try {
            String query = "select expand(shortestPath) from (select shortestPath(#9:0,#9:1,BOTH))";
            Iterable<OrientVertex> res = g.command(new OCommandSQL(query)).execute();

            while(res.iterator().hasNext()){
                OrientVertex v = res.iterator().next();
                System.out.println("rid: "+v.getId().toString());
            }

        } finally { 
            g.shutdown();
        }

    }

}
rid: #9:0
rid: #10:0
rid: #12:0
rid: #9:1

你用的是什么版本?你能发布你的完整代码并输出吗。你有什么错误吗?谢谢你的帮助,我试着用你的代码来做,但是没有结果。你可以把整个过程放在我的文件里,也许会发现一些错误,我已经添加了完整的代码。请注意,我的问题与你的略有不同。