在 vertx 中使用 updateWithParms 从 JsonArray 插入数据

Insert data from a JsonArray using updateWithParms in vertx

可以在 vertx postgres 客户端中使用 updatewithparms() 将数据插入 json 数组。我尝试了以下但没有成功。

String  INSERT_QUERY="INSERT INTO testDb (rid , aid , created_at, expiry_time, strings , strings) VALUES"

private JsonArray preparedParameters(){
    //JsonArray params = new JsonArray();
    DateTimeFormatter dateTimeFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    return new JsonArray()
            .add(device.getRecordId().toString())
            .add( device.getAccountId())
            .add(dateTimeFormat.format(device.getCreatedAt()))
            .add(dateTimeFormat.format(device.getExpiresAt()))
            .add( device.getEnrollmentId())
            .add(device.getHashedEnrollmentId());
}

然后我调用函数如下。

try (SQLConnection connection = connectionResult.result()) {
        connection.updateWithParams(INSERT_QUERY,preparedParameters() ,queryRes -> {
            if (queryRes.succeeded()) {
                booleanFuture.complete(true);
            } else {
                booleanFuture.complete(false);
            }
        });
    } catch (Exception e) {

        booleanFuture.complete(false);
    }

我收到以下错误。

The query contains 0 parameters but you gave it 6 ("sda","sda",2018-01-22 20:23:26,2018-02-21 20:23:26,"sda","sda")

com.github.mauricio.async.db.exceptions.InsufficientParametersException:查询包含0个参数但你给了它6个("sda","sda",2018-01-22 20:23:26,2018-02-21 20:23:26,"sda","sda")

您的查询无效,缺少参数。

String  INSERT_QUERY="INSERT INTO testDb (rid , aid , created_at, expiry_time, strings , strings) VALUES (?,?,?,?,?,?)"

请参阅 Vert.x SQL 文档的 Prepared Statement Updates 部分。