简体   繁体   中英

What is the syntax of parameters in cypher query in prepared statement with neo4j jdbc driver and neo4j 4?

I understand that neo4j 4.x now does not support parameters with such syntax - {1} and now supports $param. Has the syntax to execute preparedStatement also changed. What I mean by this is - when I try to execute query such as with new jdbc driver 4.0.1 and neo4j 4.2.3:

  String query = "MATCH (u:User)-[:FRIEND]-(f:User) WHERE u.name = {1} RETURN f.name, f.age";
    try (PreparedStatement stmt = con.prepareStatement(query)) {
        stmt.setString(1,"John");

        try (ResultSet rs = stmt.executeQuery()) {
            while (rs.next()) {
                System.out.println("Friend: "+rs.getString("f.name")+" is "+rs.getInt("f.age"));
            }
        }
    }

I get this error - ParameterIndex does not correspond to a parameter marker in the SQL statement

Hence is the syntax of {1} in prepared statement query with newer version of neo4j 4.2.3 and jdbc driver 4.0.1 still valid or are there any changes needed? If otherwise then could you also suggest what could be the error here. Thanks in advance !

The {param} syntax does not work for Neo4j 4.x. Instead, you need to change to the $param-style. That means, if you change {1} to $1 in your cypher query, the prepared statemen will work again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM