import java.util.Properties; import java.sql.*; /** * Bug: 29979 * Test case. * Connector/J reports wrong number of affected rows on PreparedStatement.executeUpdate() for * an insert statement against mysql-server 5.1. It is working correctly against 5.0.41 * server however. * @author Gokhan Demir gokhan.demir@modernus.com.tr */ public class WrongAffectedRows { private static final String MYURL = "jdbc:mysql://localhost:3306/test"; public static void main(String[] args) { Connection conn = null; PreparedStatement psCreate = null, psIns = null, psDrop = null; try { DriverManager.registerDriver((Driver) Class.forName("com.mysql.jdbc.Driver").newInstance()); Properties props = new Properties(); props.put("user", "root"); props.put("password", ""); conn = DriverManager.getConnection(MYURL, props); psCreate = conn.prepareStatement( "create table test.t1 (a int, vv varchar(10), primary key (a)) engine=myisam" ); psIns = conn.prepareStatement( "insert into test.t1 (a,vv) values (1,'test')" ); psDrop = conn.prepareStatement( "drop table test.t1" ); int c = psCreate.executeUpdate(); int i = psIns.executeUpdate(); int i2 = conn.createStatement().executeUpdate("insert into test.t1 (a,vv) values (2,'tttt')"); int d = psDrop.executeUpdate(); System.out.println("create ps returned = " + c); System.out.println("insert ps returned = " + i); System.out.println("insert statement returned = " + i2); System.out.println("drop ps returned = " + d); } catch (Exception e) { e.printStackTrace(); } finally { try { if (psCreate != null) psCreate.close(); if (psIns != null) psIns.close(); if (psDrop != null) psDrop.close(); if (conn != null) conn.close(); } catch (SQLException e) { System.err.println( e ); } } } }