Bug #29865 PreparedStatement.executeUpdate() return wrong number of affected rows
Submitted: 18 Jul 2007 9:26 Modified: 18 Jul 2007 9:30
Reporter: Hakan Küçükyılmaz Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:5.1 bk OS:Linux
Assigned to: CPU Architecture:Any

[18 Jul 2007 9:26] Hakan Küçükyılmaz
Description:
PreparedStatement.executeUpdate() return wrong number of affected rows.

This bug leads to Pushbuild failures.

How to repeat:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class BinaryTestExtracted {

    public static void main(String args[]) {
        String dbUrl = "jdbc:mysql:///test";
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        Statement stmt = null;
        String dbClass = "com.mysql.jdbc.Driver";

        try {
            Class.forName(dbClass).newInstance();

            conn = DriverManager.getConnection(dbUrl, "root", "");
            stmt = conn.createStatement();
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            stmt.executeUpdate("DROP TABLE IF EXISTS t1");
            stmt.executeUpdate("CREATE TABLE t1 (a varchar(4), b int, c int, PRIMARY KEY (a, b))");

            String query = "INSERT INTO t1 (a, b, c) VALUES (?,?,?)";
            pstmt = conn.prepareStatement(query);

            for (int i = 1; i < 5; i++) {
                pstmt.setString(1, "SHRT");
                pstmt.setInt(2, i);
                pstmt.setInt(3, i);
                int updateCount = pstmt.executeUpdate();

                if (updateCount != 1) {
                    System.out.println("updateCount: " + updateCount);
                    System.out.println("Insert failed in loop count " + i);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

hakan@lu0011:~/work/mysql/java$ java -cp mysql-connector-java-5.0.5-bin.jar:. BinaryTestExtracted
updateCount: 8791901
Insert failed in loop count 1
updateCount: 8791901
Insert failed in loop count 2
updateCount: 8791901
Insert failed in loop count 3
updateCount: 8791901
Insert failed in loop count 4
[18 Jul 2007 9:30] Sveta Smirnova
Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments to the original bug instead.

Thank you for your interest in MySQL.

Duplicate of Bug #29692.