Why is there no batchSelect in JDBC?
Is there some good way to handle select for multiple keys or ids?
Creating a query matching the length of all possible keys seem silly, because the database couldn’t reuse prepared statements. Using stored procedures is very database dependant.
Are their any better ways?
Use the
INclause. E.g.This returns the entities having an
idof1,13and42in aResultSetwith 3 rows.Using the
INclause in a JDBCPreparedStatementis however not exactly trivial. As to how to do this, check this question: What is the best approach using JDBC for parameterizing an IN clause?