I want to use java prepared statement with LIKE keyword. I'm trying to match a date string. Heres my code.
String summaryChooser = "SELECT * FROM PRODUCT p, CODE_COVERAGE_SUMMARY s WHERE "
+ " p.product_id = s.product_id AND p.product_id = ? AND s.date LIKE ? "
+ " ORDER BY s.date DESC LIMIT 1 ";
ps = dbConnection.prepareStatement(summaryChooser);
ps.setInt(1, productsResult.getInt("product_id"));
ps.setString(2, "%" + date + "%");
It gives below exception.
com.mysql.jdbc.exceptions.jdbc4.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 '? AND s.date LIKE ? ORDER BY s.date DESC LIMIT 1' at line 1