我有这个 sql 查询:
INSERT INTO `Items`
(`id`,`parent_id`,`name`)
VALUES (123,321,null)
ON DUPLICATE KEY UPDATE
`id` = `id`, `parent_id` = VALUES(`parent_id`), `name` = VALUES(`name`);
我用 phpmyadmin 运行查询,它返回了正确的结果:
0 - No update
1 - Line inserted
2 - Line updated
但是当我通过 java/jdbc 运行查询时,查询返回 1-1-2 ,即根本没有插入/更新时返回 1。任何想法?这是一个错误还是我只是错过了什么?
更新:最新的连接器/j - v5.1.26
更新2:Java代码
int ans1 = 0;
int ans2 = 0;
try {
java.sql.Connection c = DbConnector.getConn();
Statement s = c.createStatement();
ans1 = DbConnector.execute("INSERT INTO `Items` (`id`,`parent_id`,`name`) VALUES (123,9990635,null) ON DUPLICATE KEY UPDATE `id` = `id`, `parent_id` = VALUES(`parent_id`), `name` = VALUES(`name`);");
ans2 = DbConnector.execute("INSERT INTO `Items` (`id`,`parent_id`,`name`) VALUES (123,9990635,null) ON DUPLICATE KEY UPDATE `id` = `id`, `parent_id` = VALUES(`parent_id`), `name` = VALUES(`name`);");
s.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(ans1);
System.out.println(ans2);