org.postgresql.util.PSQLException:错误:graph_path为NULL

时间:2018-04-04 08:54:43

标签: java agens-graph

我认为agens-graph是一个很好的图形数据库,我做了一些演示。但它不起作用。有人帮我吗?

Class.forName("net.bitnine.agensgraph.Driver");
        String connectionString = "jdbc:agensgraph://127.0.0.1:5433/agens";
        Properties properties = new Properties();
        properties.setProperty("username","agens");
        properties.setProperty("password","123456");
        properties.setProperty("graph_path","graphname");
        properties.setProperty("user","agens");
        Connection conn = DriverManager.getConnection(connectionString,properties);
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(
                "MATCH (n:person {name: 'Tom'})-[:knows]->(m:person) RETURN n.name AS n, m.name AS m;");
        while (rs.next()) {
            Vertex friend = (Vertex) rs.getObject(1);
            System.out.println(friend.getString("n"));
            System.out.println(friend.getInt("m"));
        }

控制台:

Exception in thread "main" org.postgresql.util.PSQLException: ERROR: graph_path is NULL

建议:使用SET graph_path     at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2477)     at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2190)     at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:300)     在org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)     在org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)     at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301)     在org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287)     at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264)     在org.postgresql.jdbc.PgStatement.executeQuery(PgStatement.java:231)     at net.bitnine.agensgraph.jdbc.AgStatement.executeQuery(AgStatement.java:43)     在agensgraph.AgensgraphTest.main(AgensgraphTest.java:18)

1 个答案:

答案 0 :(得分:0)

您需要设置要在其上执行查询的图形:

ResultSet rs = stmt.executeQuery(
             "SET graph_path=mygraph;"+
             "MATCH (n:person {name: 'Tom'})-[:knows]->(m:person) RETURN n.name AS n, m.name AS m;"
);

其他可能性是为用户设置默认图形路径:

ALTER USER agens SET graph_path = 'mygraph';