Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 229
Romit Kumar Avatar asked Apr 30 '26 19:04

Romit Kumar


1 Answers

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.

like image 169
Stefan Armbruster Avatar answered May 03 '26 10:05

Stefan Armbruster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!