I have a question if it is possible to get parameters from SQL query in JOOQ -java.
I am using something like this:
for (Query query: sqlQueries){
for (Param param: query.getParams().values()) {
System.out.println("P: "+ param.getName());
}
}
SQL query:
...
insert into `filetest` (`Priezvisko`, `Meno`, `Vek`) values ('Kotov', 'Peter', '22');
insert into `filetest` (`Priezvisko`, `Meno`, `Vek`) values ('Alhambra', 'Seat', '33');
insert into `filetest` (`Priezvisko`, `Meno`, `Vek`) values ('F50', 'Ferrari', '100');
Will process like that (output):
P: Kotov
P: Peter
P: 22
P: Alhambra
P: Seat
P: 33
P: F50
P: Ferrari
P: 100
What I also need is to get output with column names like this:
P: Priezvisko
P: Meno
P: Vek
P: Kotov
P: Peter
P: 22
... rest
Is it possible because I could not figure it out how? If I can ask is it even possible to get tableName from query ? ('filetest' in our example)
Why I need this is to get those paramaters to create CSV file (SQL -> CSV) From mentioned SQL create CSV:
Meno,Priezvisko,Vek
"Peter","Kotov","22"
"Seat","Alhambra","33"
"Ferrari","F50","100"
The fact that a specific parameter happens to be "linked" to a column in your SQL statement is a rather arbitrary assumption of yours. A simple example that would break your assumption is this statement:
insert into `filetest` (`Priezvisko`, `Meno`, `Vek`)
values ((select 'Kotov' from dual where 1 = 0), 'Peter', '22');
This statement would now contain 5 parameters:
P: Kotov -- Relevant
P: 1 -- Irrelevant
P: 0 -- Irrelevant
P: Peter -- Relevant
P: 22 -- Relevant
You probably want to work with the generated FiletestRecord
, which is essentially a Map<Field<?>, ?>
that can be translated to INSERT
or UPDATE
statements by calling record.insert()
or record.update()
or
ctx.insertInto(FILETEST).set(filetestRecord).execute();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.