我正在使用 MySQL 数据库并通过 Java 访问它。
PreparedStatement prep1 = this.connection.prepareStatement(
"UPDATE user_table
SET Level = 'Super'
WHERE Username = ?");
prep1.setString(1, username);
上面的更新语句工作正常,但是我想获取受此语句影响的行数。请问这样可以吗?
最佳答案
Statement.executeUpdate()
或 execute()
紧随其后的是 getUpdateCount()
根据 JDBC 规范,将返回匹配的行数,而不是更新的行数。如果要更新计数,可以指定 useAffectedRows=true
作为 non-standard URL option .更多信息可用here .
关于java - 返回 Java 中受 SQL UPDATE 语句影响的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2571915/