Mysql:update返回0?

2022-11-07  本文已影响0人  Taoyongpan

Mysql:useAffectedRows参数

官方解释

useAffectedRows
Don’t set the CLIENT_FOUND_ROWS flag when connecting to the server (not JDBC-compliant, will break most applications that rely on “found” rows vs. “affected rows” for DML statements), but does cause “correct” update counts from “INSERT … ON DUPLICATE KEY UPDATE” statements to be returned by the server.
Default: false

谷歌翻译
连接到服务器时不要设置 CLIENT_FOUND_ROWS 标志(不符合 JDBC,会破坏大多数依赖于 DML 语句的“找到”行与“受影响行”的应用程序),但确实会导致“正确”更新计数来自“ INSERT ... ON DUPLICATE KEY UPDATE”语句将由服务器返回。

说人话

吸取教训

    @Test
    public void updateTest(){
        TestUpdate testUpdate = new TestUpdate();
        testUpdate.setId(1L);
        testUpdate.setName("tao");
        int num = testUpdateDao.update(testUpdate);
        if (num > 0){
            System.out.println("Success");
        }
    }
上一篇下一篇

猜你喜欢

热点阅读