Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one see the SQL statements that jOOQ executes?

Tags:

java

sql

jooq

I use jOOQ to query/insert/update data from/into a table.

Is there a way to see the SQL statements that JOOQ executes?

like image 771
user1455204 Avatar asked Jun 14 '12 03:06

user1455204


People also ask

How do you display statements in SQL?

The DISPLAY command must be placed immediately after the query statement on which you want it to take effect. For example: SELECT pno, pname FROM part WHERE color='BLUE'; DISPLAY; When the system encounters this DISPLAY command, it displays the Result window containing the part number and name for all blue parts.

How SQL statements are executed?

In order to execute an SQL statement, you must first prepare the SQL statement. During preparation, the database will usually precompile the SQL statement and creates an access plan for the statement. The access plan is kept as long as the statement exists. You can then execute the statement as many times as you want.

Which are 3 different types of SQL statements that you can execute?

Data Manipulation Language (DML) Statements. Transaction Control Statements. Session Control Statements.


1 Answers

Look for your log configuration file (or create one) and set the log level of the class org.jooq.tools.LoggerListener as debug or trace, e.g. into log4j.properties.

In spring you can set the log level DEBUG into your application.properties this way

logging.level.org.jooq.tools.LoggerListener=DEBUG

For the following query

create.select(BOOK.ID, BOOK.TITLE).from(BOOK).orderBy(BOOK.ID).limit(1, 2).fetch();

you should get a log like

Executing query          : select "BOOK"."ID", "BOOK"."TITLE" from "BOOK" order by "BOOK"."ID" asc limit ? offset ?
-> with bind values      : select "BOOK"."ID", "BOOK"."TITLE" from "BOOK" order by "BOOK"."ID" asc limit 2 offset 1
like image 180
Maurizio Lo Bosco Avatar answered Nov 03 '22 21:11

Maurizio Lo Bosco