I'm using this query manually and it works fine, what I'm missing? If I don't use WHERE, it executes perfectly.
for (ArrayList<String> match : matches) {
System.out.println(match.get(0));
// String
// 7412095225787794836
String query1 = "SELECT COUNT(*) FROM `matches_players` WHERE `match_id` = ?";
PreparedStatement preparedStmt1 = (PreparedStatement) conn.prepareStatement(query1);
preparedStmt1.setString(1, match.get(0));
ResultSet rs1 = preparedStmt1.executeQuery(query1);
// 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
while (rs1.next()) {
System.out.println("players=" + rs1.getInt("COUNT(*)"));
}
}
asked Oct 11, 2014 at 16:10
Kenny
1,1524 gold badges14 silver badges42 bronze badges
1 Answer 1
I don't think the executeQuery method takes an argument. The SQL text has already been supplied in the prepare. Try removing the argument from the executeQuery method.
Replace this:
ResultSet rs1 = preparedStmt1.executeQuery(query1);
^^^^^^
With this:
ResultSet rs1 = preparedStmt1.executeQuery();
And see how big a smoke ball that makes.
answered Oct 11, 2014 at 16:28
spencer7593
109k15 gold badges122 silver badges148 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default
match_idcolumn haveINTtype? Can you trypreparedStmt1.setInt(1, match.get(0).intValue());