public List<Product> getListOfProductsWhere(String name, int productscol, double cost, String check) { List<Product> listOfProducts = jdbcTemplateObject.query(SELECT * FROM products WHERE name LIKE %?%, returnArray(name, productscol, cost, check), new RowMapper<Product>() { @Override public Product mapRow(ResultSet rs, int rowNum) throws SQLException { Product product = new Product(); product.setId(rs.getInt("id")); product.setName(rs.getString("name")); product.setDate(rs.getDate("date")); product.setProductscol(rs.getInt("productscol")); product.setCost(rs.getDouble("cost")); product.setId_user(rs.getInt("users_user_id")); return product; } }); return listOfProducts; } 

Mistake

Mon Apr 25 23:40:21 SAMT 2016 There was an unexpected error (type = Internal Server Error, status = 500). PreparedStatementCallback; bad SQL grammar [SELECT * FROM products WHERE name LIKE%?%]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the syntax for your right syntax to use the '%' chocolate '% at line 1

  • Maybe add your description of the code and the problem, and not just copy-paste? - AivanF.

1 answer 1

bad SQL grammar [SELECT * FROM products WHERE name LIKE%?%

This error means that the percent signs should not belong to the query itself, as in your example, but to the query argument. Accordingly, it will be necessary to further process the incoming argument and add the percent signs to it from both sides.

By the way, do not forget to also screen these same percent signs in the argument itself.