Home  >  Q&A  >  body text

java - MYSQL5.6 ROW_COUNT()返回不一致

表t_test中已存在id = 97并且num = 2的记录

重复执行以下SQL:

UPDATE t_test SET num = 2 WHERE id = 97;
select ROW_COUNT();

在navicat for mysql或者mysql workbench中,ROW_COUNT()=0,但是在java程序(dbutils框架)中总是返回1,有没有大神解释一下?

高洛峰高洛峰2762 days ago389

reply all(1)I'll reply

  • 黄舟

    黄舟2017-04-18 09:07:55

    The normal code is to return 0, because the meaning of this value is the number of affected rows. Since the original value here is already 2, the result of the number of affected rows is 0, which is correct.
    I don’t know much about this framework. I guess the reason is as follows:
    Because the framework considers that the result here is generally used as a sign to judge whether the operation is successful or not. If it keeps returning 0, it will enter the wrong logic, so most frameworks will be re-modified. this value.

    reply
    0
  • Cancelreply