Reader small image

You're reading from  jOOQ Masterclass

Product typeBook
Published inAug 2022
Reading LevelBeginner
PublisherPackt
ISBN-139781800566897
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Anghel Leonard
Anghel Leonard
author image
Anghel Leonard

Anghel Leonard is a Chief Technology Strategist and independent consultant with 20+ years of experience in the Java ecosystem. In daily work, he is focused on architecting and developing Java distributed applications that empower robust architectures, clean code, and high-performance. Also passionate about coaching, mentoring and technical leadership. He is the author of several books, videos and dozens of articles related to Java technologies.
Read more about Anghel Leonard

Right arrow

Expressing DELETE statements

Expressing DELETE statements in jOOQ can be done via the DSLContext.delete() and DSLContext.deleteFrom() API or via DSLContext.deleteQuery() and DSLContext.executeDelete(), respectively. While the first three methods receive an argument of the Table<R> type, the executeDelete()method is useful for deleting a record as TableRecord<?> or UpdatableRecord<?>. As you can see from the following example, delete() and deleteFrom() work exactly the same:

ctx.delete(SALE)
   .where(SALE.FISCAL_YEAR.eq(2003))
   .execute();
ctx.deleteFrom(SALE)
   .where(SALE.FISCAL_YEAR.eq(2003))
   .execute();

Both of these expressions render this SQL:

DELETE FROM `classicmodels`.`sale`
WHERE `classicmodels`.`sale`.`fiscal_year` = ?

Combining DELETE and row value expressions is useful for deleting via subselects, as in the following example:

ctx.deleteFrom(CUSTOMERDETAIL)
   ...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
jOOQ Masterclass
Published in: Aug 2022Publisher: PacktISBN-13: 9781800566897

Author (1)

author image
Anghel Leonard

Anghel Leonard is a Chief Technology Strategist and independent consultant with 20+ years of experience in the Java ecosystem. In daily work, he is focused on architecting and developing Java distributed applications that empower robust architectures, clean code, and high-performance. Also passionate about coaching, mentoring and technical leadership. He is the author of several books, videos and dozens of articles related to Java technologies.
Read more about Anghel Leonard