jOOQ使用Where子句更新查询

时间:2013-10-30 08:53:30

标签: java sql jooq

如何在jOOQ中添加Where子句和更新查询?

AccountPaymentRecord aacntPaymentRec = new AccountPaymentRecord();
aacntPaymentRec.setReceiptNumber(PaymentNumberFrom);
aacntPaymentRec.setPaymentComment(ReasonFrom);
transfeeTransfer.update(aacntPaymentRec);

我还必须添加Where子句。怎么做?

2 个答案:

答案 0 :(得分:1)

由于您在UpdatableRecord上操作,因此您可能需要关注what's documented here, in the manual。另一个查找信息的地方是jOOQ manual's sections about the UPDATE statement

您可能的解决方案:

使用您已启动的代码,一种可能的解决方案是使用DSLContext.executeUpdate(R, Condition)

AccountPaymentRecord aacntPaymentRec = new AccountPaymentRecord();
aacntPaymentRec.setReceiptNumber(PaymentNumberFrom);
aacntPaymentRec.setPaymentComment(ReasonFrom);
DSL.using(configuration)
   .executeUpdate(aacntPaymentRec, ACCOUNT_PAYMENT.ID.eq(123));

答案 1 :(得分:1)

在我的情况下感谢@Lukas,我必须像这样使用

AccountPaymentRecord aacntPaymentRec = transfeeTransfer.fetchOne(AccountPayment.ACCOUNT_PAYMENT,
                AccountPayment.ACCOUNT_PAYMENT.PAYMENT_NUMBER.eq(PaymentNumberTo));
aacntPaymentRec.setReceiptNumber(PaymentNumberFrom);
aacntPaymentRec.setPaymentComment(ReasonFrom);
aacntPaymentRec.update();