J Fabian Meier
J Fabian Meier

Reputation: 35785

Execute cypher query (Neo4j) from java

I would like to query a Neo4j server by sending a Cypher query to it and receive the output as some kind of table.

I have read that people using RestCypherQueryEngine, but the neo4j-contrib/java-rest-binding says on github that "this library is no longer maintained".

So what is the usual, non-deprecated way to contact a Neo4j server from java (via REST?), send it a Cypher query with parameters, receive the result and interpret it as some kind of table?

Upvotes: 2

Views: 3534

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35785

It seems that the Neo4j Java Driver is the preferred way to execute Cypher queries.

https://neo4j.com/developer/java/#neo4j-java-driver

Queries can be run as

StatementResult result = session.run( "MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title" );
while ( result.hasNext() )
{
    Record record = result.next();
    System.out.println( record.get( "title" ).asString() + " " +  record.get("name").asString() );
}

Upvotes: 5

Related Questions