gpt4 book ai didi

Java - 查询不返回结果

转载 作者:行者123 更新时间:2023-12-01 16:47:23 25 4
gpt4 key购买 nike

java.sql.SQLException: Query does not return results

这是我运行代码时遇到的错误。

我正在制作一个在数据库上运行的井字棋游戏。我正在用这段代码制作一个空板。

关于为什么数据库没有更新的任何想法?

//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();
}

最佳答案

您应该使用preparedStatement.executeUpdate()。请参阅文档 here.

方法.executeQuery()仅用于SELECT操作,或者一般用于返回某些内容的任何查询。相反,如果您想要修改数据库,则必须使用.executeUpdate()

关于Java - 查询不返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47724374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com