Error in Executing Neo4j Cypher Query (by Java) embedded mode

*爱你&永不变心* 提交于 2019-12-10 10:13:30

问题


Im having error in executing Cypher query in java (embedded mode) This is my code:

    import org.neo4j.cypher.internal.ExecutionEngine;
    import org.neo4j.cypher.internal.ExecutionResult;
    import org.neo4j.graphdb.GraphDatabaseService;
    import org.neo4j.graphdb.factory.GraphDatabaseFactory;
    public class test {
    public static void main(String[] args) {
    GraphDatabaseFactory graphdbFactory = new GraphDatabaseFactory();
    GraphDatabaseService graphdb = new graphdbFactory.newEmbeddedDatabase("C:/Users/dell/Documents/Neo4j");    
    ExecutionEngine execEngine = new ExecutionEngine(graphDb);
    ExecutionResult execResult = execEngine.execute
               ("MATCH (java:JAVA) RETURN java");
    String results = execResult.dumpToString();
    System.out.println(results);
}

}

Im getting error at the line : GraphDatabaseService graphdb = new graphdbFactory.newEmbeddedDatabase("C:/Users/dell/Documents/Neo4j"); error: the method new embedded database (file) in the type graph database factory is not applicable for the arguments (string)

please help


回答1:


GraphDatabaseFactory.newEmbeddedDatabase() expects a File and not a String, see http://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/graphdb/factory/GraphDatabaseFactory.html#newEmbeddedDatabase-java.io.File-

Also there's no need to use ExecutionEngine. Just do a graphDb.execute(<cypherString>). Note this applies to Neo4j >= 2.3.




回答2:


Below code should work to fix the issue.

File storeFile = new File("C:/Users/dell/Documents/Neo4j");

GraphDatabaseService db= dbFactory.newEmbeddedDatabase(storeFile);



来源:https://stackoverflow.com/questions/37875024/error-in-executing-neo4j-cypher-query-by-java-embedded-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!