DEV Community

ts5432
ts5432

Posted on

Delete record using JooqTemplate

1. delete

Delete records matching the given condition.

// Single Condition
public int delete(String table, Condition condition)
public int delete(Table table, Condition condition)
// List<Condition>
public int delete(String table, List<Condition> conditions)
public int delete(Table table, List<Condition> conditions)
Enter fullscreen mode Exit fullscreen mode

Returns: int — number of affected rows.
Example:

jt.delete("user_table", F("id").eq(100));
jt.delete("user_table", Arrays.asList(F("id").eq(100)));
Enter fullscreen mode Exit fullscreen mode

2. deletev (varargs conditions)

Specify delete conditions via varargs.

public int deletev(String table, Object... conditions)
public int deletev(Table table, Object... conditions)
Enter fullscreen mode Exit fullscreen mode

Returns: int — number of affected rows.
Example:

// Delete by equality
jt.deletev("user_table", "id", 100);

// Multiple conditions  WHERE name = ? AND birthday >= ?
jt.deletev("user_table", "name", "John", "birthday>=", beginDate);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)