Code_Panda
Code_Panda

Reputation: 5

Replace a String in a MySQL table using JOOQ

UPDATE table
SET field = REPLACE(your_field, 'original_string', 'replace_string')
WHERE your_field LIKE '%original_string%'

Is there a way I could execute above query with JOOQ?

Upvotes: 0

Views: 568

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 221106

Yes, it translates pretty much 1:1. Just write it out like this:

using(configuration)
  .update(TABLE)
  .set(TABLE.FIELD, 
       replace(TABLE.YOUR_FIELD, "original_string", "replace_string"))
  .where(TABLE.YOUR_FIELD.like("%original_string%"))
  .execute();

The DSL.replace() method is documented in the Javadoc

The following static imports are assumed:

import static org.jooq.impl.DSL.*;
import static com.example.your.schema.Tables.*;

Upvotes: 3

Related Questions