neo4jcypherjdbctemplateneo4j-java-api

Neo4j delete a node property with neo4j-jdbc


I have an edge with sevral properties. I would like to keep the edge but remove only the name property.

My java Cypher is this :

public static final String DELETE_EDGE_PROPERTY_QUERY = //
        "MATCH ()-[r]->() where id(r) = {1} REMOVE r.{2} RETURN r"; //

It works on cypher console but doesn't work on jdbc.

I got this error :

processing failed; nested exception is org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [MATCH ()-[r]->() where id(r) = {1} REMOVE r.{2} RETURN r]; SQL state [null]; error code [0]; Some errors occurred : [Neo.ClientError.Statement.SyntaxError]:Invalid input '{': expected an identifier, whitespace, a function name or a property key name (line 1, column 45 (offset: 44)) "MATCH ()-[r]->() where id(r) = {1} REMOVE r.{2} RETURN r" `

Any suggestions?

Thanks

EDIT

I couldn't do with jdbc template. so I have used String replacement: Setting the property to NULL will delete the property (http://www.baeldung.com/java-neo4j)

Solution : Java :

String deleteQuery = String.format(DELETE_EDGE_PROPERTY_QUERY, property);
plantJdbcTemplate.update(deleteQuery, edgeId);

cypher :

public static final String DELETE_EDGE_PROPERTY_QUERY = //
        "MATCH ()-[r]->() where id(r) = {1} SET r.%s = NULL RETURN r";

Solution

  • This not a neo4j-jdbc issue, it's related to the design of Neo4j about parameterized query.

    On a query you can parameterized all data you want, except:

    If you want to do it in Cypher, there are a lot of helpers in the APOC plugin.