天天看點

java sql update 語句,傳回受Java中SQL UPDATE語句影響的行數

java sql update 語句,傳回受Java中SQL UPDATE語句影響的行數

I'm using a MySQL database and accessing it through Java.

PreparedStatement prep1 = this.connection.prepareStatement("UPDATE user_table

SET Level = 'Super'

WHERE Username = ?");

prep1.setString(1, username);

The update statement above works fine however I'd like to get the number of rows affected with this statement. Is this possible please?

解決方案

Calling executeUpdate() on your PreparedStatement should return an int, the number of updated records.