Forced to correct previous speakers. Everything is true except for one, the formation of almost identical requests without the use of PreparedStatement is anti-pattern.
I explain. PreparedStatement request to precompile a stable SQL expression, so the next time the DBMS is called, it will not recompile the SQL query, but will only change the call parameters by retrieving the query from its cache, which is much faster in time + bonus protection from SQL injection
Closer to the code:
String selectSQL = "SELECT * FROM TABLE_NAME WHERE CODE = ?"; String whereClause="blah-blah"; PreparedStatement preparedStatement = dbConnection.prepareStatement(selectSQL);
And now it is already possible to form the string whereClause method proposed by StringJoiner through StringJoiner or StringBuilder substituting it in PreparedStatement and calling the actual request itself (without changing the PreparedStatement object each time):
preparedStatement.setString(1, whereClause); ResultSet rs = preparedStatement.executeQuery(selectSQL );
SELECT * FROM "TABLE_NAME" WHERE CODE="code012"did not try? - GardenManSELECT * FROM "TABLE_NAME" WHERE CODE="code012" or CODE="code876" ...Get all the strings from the database - GardenMan