Java: 如何在 sql 查询中使用多个参数在 jdbc 中执行 preparedStatement?

Java: How to execute preparedStatement in jdbc with multiple parameters in sql query?

这就是我想要做的:

PreparedStatement query2 = 
conn.prepareStatement ("UPDATE report SET Name = ? WHERE Id = ?");

String blah = "Jane";
int id = 1;

query2.setString(1, blah);
query2.setInt(2, id);
query2.executeQuery();

但是我收到这个错误:

The statement did not return a result set.

我是整个 jdbc 世界的新手。我哪里错了?

你应该使用 executeUpdate.

"Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement."