返回受Java中SQL UPDATE语句影响的行数 [英] Return number of rows affected by SQL UPDATE statement in Java

查看:592
本文介绍了返回受Java中SQL UPDATE语句影响的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MySQL数据库并通过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?

推荐答案

调用 executeUpdate()在PreparedStatement上应返回一个int,即更新记录的数量。

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

这篇关于返回受Java中SQL UPDATE语句影响的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆