Skip to content

Query listener

Zsolt Herpai edited this page Feb 5, 2016 · 4 revisions

Query listener - if configured - will be called after each SQL query (whether successful or not). This may be used for logging, performance monitoring, error recovery. A simple example that logs all successfully executed SQL queries along with their execution time:

AfterQueryListener listener = execution -> {
    if(execution.success()) {
        log.debug(
            String.format(
                "Query took %s ms to execute: %s",
                execution.executionTimeMs(),
                execution.sql()
            )
        )
    }
};

FluentJdbc fluentJdbc = new FluentJdbcBuilder()
    // other configuration
    .afterQueryListener(listener)
    .build();

// run queries

Note: Check out the Javadoc for more details on AfterQueryListener.