I need to write a query for a MySQL database using jdbc that depends on some business logic, which can be summarized as something like this
if (someCondition) {
myQuery = "stuff";
} else {
if (anotherCondition) {
myQuery = "some stuff";
} else {
myQuery = "even more stuff";
}
}
And I intend to build the myQuery string to serve as a template for a PreparedStatement object and then fill the ? with the actual data. however, the number of ? depends on the same logic as above, and therefore I'm duplicating the logic in the code
How can I avoid it?
Thanks
myQueryand keep appending those. Then use that to prepare the statement,