简体   繁体   English

使用 neo4j jdbc 驱动程序和 Z767EC634238039F6EZ61EB4B 的准备语句中的 cypher 查询中的参数语法是什么?

[英]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.我了解 neo4j 4.x 现在不支持具有这种语法的参数 - {1},现在支持 $param。 Has the syntax to execute preparedStatement also changed.执行preparedStatement 的语法也发生了变化。 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:我的意思是 - 当我尝试使用新的 jdbc 驱动程序 4.0.1 和 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我收到此错误 - ParameterIndex 与 SQL 语句中的参数标记不对应

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?因此,使用较新版本的 neo4j 4.2.3 和 jdbc 驱动程序 4.0.1 的准备好的语句查询中的 {1} 语法仍然有效还是需要进行任何更改? 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. {param} 语法不适用于 Neo4j 4.x。 Instead, you need to change to the $param-style.相反,您需要更改为 $param 样式。 That means, if you change {1} to $1 in your cypher query, the prepared statemen will work again.这意味着,如果您在 cypher 查询中将{1} 更改为 $1 ,则准备好的语句将再次起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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