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
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