通过JDBC执行INSERT IGNORE时获取重复计数 [英] Getting duplicate count when executing INSERT IGNORE via JDBC

查看:186
本文介绍了通过JDBC执行INSERT IGNORE时获取重复计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过JDBC执行MySQL"INSERT IGNORE"语句时,是否可以获得重复计数?

Is it possible to get the duplicate count when executing MySQL "INSERT IGNORE" statement via JDBC?

例如,当我在mysql命令行上执行INSERT IGNORE语句时,如果重复,则会得到类似

For example, when I execute an INSERT IGNORE statement on the mysql command line, and there are duplicates I get something like

查询正常,受影响的0行(0.02秒) 记录:1重复项:1警告:0

Query OK, 0 rows affected (0.02 sec) Records: 1 Duplicates: 1 Warnings: 0

请注意在其上显示重复项:1"的地方,表示存在被忽略的重复项.

Note where it says "Duplicates: 1", indicating that there were duplicates that were ignored.

通过JDBC执行查询时是否可以获得相同的信息?

Is it possible to get the same information when executing the query via JDBC?

谢谢.

推荐答案

在执行INSERT IGNORE时,可以使用ROW_COUNT()和FOUND_ROWS()函数来确定插入的行和重复项的数量.

You can use the ROW_COUNT() and FOUND_ROWS() functions to determine the number of inserted rows and duplicates when doing INSERT IGNORE.

例如:

SELECT ROW_COUNT(), FOUND_ROWS()
    INTO myRowCount, myFoundRows;
myInsertedRows = myRowCount;
myDuplicateRows =  myFoundRows - myInsertedRows;
COMMIT;

这篇关于通过JDBC执行INSERT IGNORE时获取重复计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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