java.sql.SQLException:Query不返回结果
这是我运行代码时遇到的错误。
我正在制作一个用于运行数据库的井字游戏。我正在用这段代码制作一块空板。
为什么数据库没有被更新的任何想法??
//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();
}
答案 0 :(得分:3)
您应该使用preparedStatement.executeUpdate()
代替。请参阅文档here.
方法.executeQuery()
仅用于SELECT
操作,或者通常用于返回某些内容的任何查询。相反,如果您要修改数据库,则必须改为使用.executeUpdate()
。
答案 1 :(得分:2)
ResultSet resultSet = preparedStatement.executeUpdate();
^^^^^^
ExecuteUpdate
是用于非结果返回DML的方法。