In my Java code, I want to create a long query, I find JOOQ to build query and I use it without generation class but I don't find the way to build my query step by step like this:
DSLContext request = DSL.using(sqlConnection, SQLDialect.MYSQL);
request.insertInto(DSL.table("MyTable"), DSL.field("MyColumn1"), DSL.field("MyColumn2"));
// ... some code ...
request.values("hello", 98);
// ... some code ...
request.values("world", 67);
// ... some code ...
request.execute();
How to make this ?
You have many options.
Stick with the DSL API
... and assign the intermediate types to a local variable:
Use the model API instead
... This kind of dynamic SQL is probably easier to implement using the model API (see also http://www.jooq.org/doc/latest/manual/sql-building/sql-statements/dsl-and-non-dsl)
Use a batch statement
An alternative would be to send a batch of multiple individual statements to the server by using the batch API (http://www.jooq.org/doc/latest/manual/sql-execution/batch-execution). For example:
... or, in a more dynamic form: