0

我是 JavbDB 的新手,需要简单地将字符串附加到现有的数据库单元,如下所示:

public boolean updateChildNodes(String filePath, String parentPath)
        throws SQLException {

    // Set new parent path for all child nodes
    String sql = "UPDATE sc_compare SET parentPath = (? || parentPath)"
            + "WHERE parentPath = ?";

    try (Connection connection = this.connect();
         PreparedStatement pstmt = connection.prepareStatement(sql)) {

        // set the corresponding param
        int i = 1;
        pstmt.setString(i++, parentPath);
        pstmt.setString(i++, filePath+"%");
        // update
        pstmt.executeUpdate();
    } catch (SQLException | ClassNotFoundException e) {
        System.out.println("updateChildNodes() "+e.getMessage());
        return false;
    }

    return true;
}

示例调用:

updateChildNodes("/old path/", "/new_parent");

对于现有条目“/old_path/”,我期望“/new_parent/old_path/”。

我收到一个 TAG 而不是准备好的占位符作为前置字符串。

这是否可以将准备好的字符串与 JavaDB 连接一起使用,我做错了什么?

4

0 回答 0