java.sql.SQLException: Query does not return results
This is the error I get when running my code.
I am making a tic-tac-toe game to run off of a database. I'm making an empty board with this code.
Any ideas of why the database is not being updated??
//INSERT SPACE
String space1 = "INSERT INTO space(row,column,contents) VALUES (?,?,?)";
String space2 = "INSERT INTO space(row,column,contents) VALUES (?,?,?)";
String space3 = "INSERT INTO space(row,column,contents) VALUES (?,?,?)";
String space4 = "INSERT INTO space(row,column,contents) VALUES (?,?,?)";
String space5 = "INSERT INTO space(row,column,contents) VALUES (?,?,?)";
String space6 = "INSERT INTO space(row,column,contents) VALUES (?,?,?)";
String space7 = "INSERT INTO space(row,column,contents) VALUES (?,?,?)";
String space8 = "INSERT INTO space(row,column,contents) VALUES (?,?,?)";
String space9 = "INSERT INTO space(row,column,contents) VALUES (?,?,?)";
/**
* Inserts empty space into space 1
*/
try {
PreparedStatement preparedStatement = connectDatabase.getConnection().prepareStatement(space1);
preparedStatement.setInt(1,0);
preparedStatement.setInt(2,0);
preparedStatement.setString(3, "e");
ResultSet resultSet = preparedStatement.executeQuery();
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
2 Answers 2
You should use preparedStatement.executeUpdate() instead. See the docs here.
The method .executeQuery() is only used for SELECT operations, or in general for any queries that return something. If, instead, you want to modify your database, you must use .executeUpdate() instead.
Comments
ResultSet resultSet = preparedStatement.executeUpdate();
^^^^^^
ExecuteUpdate is the method to use for non-results-returning DML.
INSERT???