简体   繁体   English

在 OrientDB 中查询

[英]Query in OrientDB

I try to print a query through the java console but nothing comes out.我尝试通过 java 控制台打印查询,但没有任何结果。 this is my code someone could help me.这是我的代码,有人可以帮助我。 I'm new to OrientDB and I'm just learning.我是 OrientDB 的新手,我只是在学习。 The query I need is to know the shortest path between two nodes and print this query on the Java console.我需要的查询是知道两个节点之间的最短路径并在 Java 控制台上打印此查询。 It does not give me any errors but nothing comes out.它没有给我任何错误,但没有任何结果。

public class Graph {
    private static final String DB_PATH = "C:/OrientDataBase/shortest_path";
    static OrientGraphNoTx DBGraph;
    static OrientGraphFactory factory;

 public static void main(String[] args) {
        factory = new OrientGraphFactory("plocal:"+DB_PATH);
        DBGraph = factory.getNoTx();
        HashMap<String, Vertex> nodes = new HashMap<String, Vertex>();

    for(int i = 0; i <= 1000; i++)
    {
        Vertex v = DBGraph.addVertex("class:V");
        v.setProperty("vertexID", i+"");
        nodes.put(i+"", v);
    }


    try(BufferedReader br = new BufferedReader(new FileReader("C:/OrientDataBase/sp1.csv"))) {
        int i=0;
        for(String line; (line = br.readLine()) !=null ; ) {
            if(i==0){
                i++;
            }
            else{
            String[] vertices = line.split(",");
            String vertex1 = vertices[0];
            String vertex2 = vertices[1];
            String weight= vertices[2];
            vertex2 = vertex2.replaceAll(" ", "");

            Vertex v1 = nodes.get(vertex1);
            Vertex v2 = nodes.get(vertex2);


            Edge eLives = DBGraph.addEdge(null, v1, v2, "belongs");
            eLives.setProperty("weight", weight);
            System.out.println(v1+","+v2+","+weight);

            String query = "select expand(shortestPath) from (select shortestPath(#10:0,#10:2,BOTH))";

            Iterable<OrientVertex> res = DBGraph.command(new OCommandSQL(query)).execute();

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

            }
        }

    }
    catch (IOException e) {
        e.printStackTrace();
    }



}
}

I tried your code and you have to put the ticks when you do the query so, it becomes:我试过你的代码,你必须在查询时打勾,它变成:

String query = "select expand(shortestPath) from (select shortestPath(#10:0,#10:2,'BOTH'))";

在此处输入图片说明

I used this csv file.我使用了这个 csv 文件。

在此处输入图片说明

Hope it helps.希望能帮助到你。

Regards问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM