Expressing INSERT statements
In this section, we will express different kinds of inserts including INSERT ... VALUES
, INSERT ... SET
, INSERT ... RETURNING
, and INSERT ...DEFAULT VALUES
via the jOOQ DSL syntax. Let's start with the well-known INSERT ... VALUES
insert, which is supported by most database vendors.
Expressing INSERT ... VALUES
jOOQ supports INSERT ... VALUES
via the insertInto()
and values()
methods. Optionally, we can use the columns()
method for separating the name of the table in which we insert from the list of fields/columns that we insert. To trigger the actual INSERT
statement, we have to explicitly call execute()
; pay attention to this aspect since jOOQ novices tend to forget this call at the end of the insert/update/delete expressions. This method returns the number of rows affected by this INSERT
statement as an integer value (0
), which means that nothing happened.
For example, the following jOOQ type-safe expression will render an INSERT
statement...