在Neo4j数据检索中获得零点异常

时间:2016-02-15 00:33:26

标签: java database neo4j

我有以下代码。

GraphDatabaseFactory dbFactory = new GraphDatabaseFactory();
GraphDatabaseService db= dbFactory.newEmbeddedDatabase("C:/Users/shadid/Documents/Neo4j/DB");

ExecutionEngine execEngine = new ExecutionEngine(db, null);
ExecutionResult execResult = execEngine.execute("MATCH (mat:TheMatrix) RETURN mat");
String results = execResult.dumpToString();
System.out.println(results);

我收到零点异常。我试过在neo4j命令行中运行命令。所以数据确实存在。我不太确定错误在哪里。在neo4j中相当一个菜鸟,所以有人可以帮帮我

这是我顺便说一句的错误

  

线程中的异常" main"显示java.lang.NullPointerException
  在org.neo4j.cypher.internal.CypherCompiler。(CypherCompiler.scala:69)
  在org.neo4j.cypher.ExecutionEngine.createCompiler(ExecutionEngine.scala:237)
  在org.neo4j.cypher.ExecutionEngine。(ExecutionEngine.scala:64)
  在App.Main.main(Main.java:53)

2 个答案:

答案 0 :(得分:1)

刚刚找到了一种更直观的方式来做同样的事情,它可以正常工作!!!

try ( Transaction ignored = db.beginTx();
                  Result result = db.execute( "MATCH (n:TheIronGiant) RETURN n.`title: `" ) )
            {
            String rows ="";
            while ( result.hasNext() )
                {
                    Map<String,Object> row = result.next();

                    for ( Entry<String,Object> column : row.entrySet() )
                    {
                        rows  += column.getKey() + ": " + column.getValue() + "; ";
                    }
                    rows += "\n";
                }
            System.out.println(rows);
            }

答案 1 :(得分:0)

  1. 您正在使用ExecutionEngine constructor作为第二个参数,但为其传递LogProvider值。如果您拨打了single-parameter constructor,而不是null,则可能无法获得例外。

  2. 此外,ExecutionEngine class现已弃用,您应该使用GraphDatabaseService.execute()代替。