String sql="select * from matrix where metric_name in(?)";
PreparedStatement st1 = conn.prepareStatement(sql);
st1.setString(1,"NO_OF_ORDERS");
resultSet = st1.executeQuery(sql);
while (resultSet.next()) {
}
The same query works fine with mysql 5.7 but I am not able to find the issue.
How do pass in parameters in mysql 5.5 from jdbc
Error is :
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 '?)' at line 1
解决方案
You should not call executeQuery(String) on a PreparedStatement, you should call executeQuery() instead. This is explicitly disallowed by the JDBC api, but only goes wrong by accident (due to the syntax error) with MySQL Connector/J.
Note that your current query is the equivalent of:
select * from matrix where metric_name = ?
I don't see a reason why you'd use IN here.