Romit Kumar
Romit Kumar

Reputation: 3300

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

Upvotes: 3

Views: 855

Answers (2)

karthik Ramidi
karthik Ramidi

Reputation: 11

Below code should work to fix the issue.

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

GraphDatabaseService db= dbFactory.newEmbeddedDatabase(storeFile);

Upvotes: 1

Stefan Armbruster
Stefan Armbruster

Reputation: 39925

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.

Upvotes: 2

Related Questions