Using bound parameters (using ?) in Prepared Statement is a popular strategy for inserting parameters in SQL queries at runtime. My question is, should this strategy be used for inserting constants into queries? I am talking about constants that are not related to the data input by user in any way. Is there any reason why I shouldn't use these constants directly in an SQL query, but use a Prepared Statement instead?
To show what I am talking about through code:
public static final String x = "xxx";
getJdbcTemplate.update("SELECT * FROM TABLE WHERE COLUMN = ?", x);
vs
getJdbcTemplate.update("SELECT * FROM TABLE WHERE COLUMN = '" + x + "'");