【问题标题】:What is the syntax of parameters in cypher query in prepared statement with neo4j jdbc driver and neo4j 4?使用 neo4j jdbc 驱动程序和 neo4j 4 准备好的语句中的密码查询参数的语法是什么?
【发布时间】:2021-03-16 11:14:10
【问题描述】:

我知道 neo4j 4.x 现在不支持具有这种语法的参数 - {1},现在支持 $param。执行preparedStatement 的语法也发生了变化。我的意思是 - 当我尝试使用新的 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"));
            }
        }
    }

我收到此错误 - ParameterIndex 与 SQL 语句中的参数标记不对应

因此,在新版本的 neo4j 4.2.3 和 jdbc 驱动程序 4.0.1 的准备语句查询中,{1} 的语法仍然有效,或者是否需要进行任何更改?如果不是这样,那么您是否还可以建议这里可能出现的错误。 提前致谢!

【问题讨论】:

  • 你试过用?代替吗?

标签: jdbc neo4j cypher


【解决方案1】:

{param} 语法不适用于 Neo4j 4.x。相反,您需要更改为 $param 样式。这意味着,如果您在密码查询中将 {1} 更改为 $1,则准备好的语句将再次起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-19
    • 2011-11-03
    • 2015-07-14
    相关资源
    最近更新 更多