如何使用多个 'set' 方法创建 'update'

How to create 'update' using multiple 'set' methods

概要: 我正在尝试使用 jOOQ

创建一个 SQL 更新
DSL.using(connection)
.update(DSL.table("dogs"))
.set(DSL.field("age"), DSL.field("age").add(1))
.set(DSL.field("rabies"), "true")
.where(DSL.field("id").eq("Kujo"))
.execute();

问题:

The method set(Field<Object>, Object) is ambiguous for the type UpdateSetFirstStep<Record>

问题:如何使用 jOOQ 创建此更新?

你运行遇到这个问题:Reference is ambiguous with generics

正在修复您的查询

在 jOOQ 表达式中附加数据类型总是一个好主意。在您的特定情况下,您可以通过指定以下内容来解决该问题:

DSL.field("age", SQLDataType.INTEGER)

或者更短,使用通常的静态导入:

field("age", INTEGER)

使用代码生成器

但是,jOOQ 最好与其 code generator, see also this article here. Not only will you avoid problems like these, but you also get compile time type safety (of data types and meta data), advanced features like implicit joins 等一起使用。

您的查询将如下所示:

DSL.using(connection)
   .update(DOGS)
   .set(DOGS.AGE, DOGS.AGE.add(1))
   .set(DOGS.RABIES, true)
   .where(DOGS.ID.eq("Kujo"))
   .execute();