Krt_Malta Krt_Malta - 1 year ago 117
SQL Question

Return number of rows affected by SQL UPDATE statement in Java

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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download