Simon Martinelli
Simon Martinelli

Reputation: 36173

Write SQL Statements to File

I use jOOQs UpdatableRecord and call updatableRecord.store() to execute the Insert or Update statements.

Now I want to save the SQL statements that are executed to a file because I need to execute these statements on another database as well.

What's the easiest way to achieve this?

Upvotes: 1

Views: 70

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 220987

You can implement your own ExecuteListener or use the built in LoggerListener (which adds some extra log content), see here: https://www.jooq.org/doc/latest/manual/sql-execution/logging.

Your own ExecuteListener could look like this:

public class Logger extends DefaultExecuteListener {
    @Override
    public void executeStart(ExecuteContext ctx) {
        MyUtils.writeToFile(ctx.sql());
    }
}

The listener is then added to your Configuration

Upvotes: 1

Related Questions