I have an sqlQuery:
select * from products where product_type in :prodTypes
query.setParameter("prodTypes",getInClauseFromList(productTypes));
productTypes is a List<String>
public String getInClauseFromList(List list) {
if(list != null && !list.isEmpty()) {
String inClause = Arrays.toString(list.toArray());
inClause = inClause.replace("[", "('").replace("]", "')");
inClause = inClause.replace(", ", "','");
return inClause;
}
return "('')";
}
I get an error:
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server version for the right
syntax to use near ''(\'clothes\')')
INclause as plain text. There is some small problem, but we need to see this.getInClauseFromList(). It will be obvious why MySQL is barfing on it.