For example if I have:
connection.prepareStatement("SELECT * FROM users
WHERE status=? AND otherAttribute=?");
Where in some cases I might want a specific status and in others I want all statuses. How can I basically do something like:
preparedStatement.setInt(1, mySpecificRequestedStatus);
and in other cases:
preparedStatement.setInt(1, allStatuses); // wildcard
So that I don’t have to have multiple PreparedStatements, especially for more complex WHERE clauses in the SELECT statements where the permutations can be higher.
You don’t have a choice, you have to pick one or the other as I originally suspected and asked.
You can either:
There really isn’t a good solution to this. This is why ORM’s exist, to abstract this out. The problem is that ORM introduce other issues/complexities in exchange for simplifying other things.