import java.sql.*; public class TestEndResultSet { public static void main(String[] args) throws SQLException, ClassNotFoundException { Connection conn=null; String database="test"; String user="user"; String password="password"; Class.forName("com.mysql.jdbc.Driver"); String URL="jdbc:mysql://localhost:3306/"+database +"?zeroDateTimeBehaviour=convertToNull&noDatetimeStringSync=true" +"&jdbcCompliantTruncation=false" ; conn = DriverManager.getConnection(URL,user,password); Statement stmt=null; ResultSet rs=null; //drop table foo String sqlStmt="drop table foo" ; try { stmt = conn.createStatement(); stmt.executeUpdate(sqlStmt); }catch (SQLException e) { } //create table sqlStmt="create table foo (" +" pkey int not null " +",value int not null " +",PRIMARY KEY (pkey) " +") ENGINE=InnoDB DEFAULT CHARSET=latin1 " ; try { stmt = conn.createStatement(); stmt.executeUpdate(sqlStmt); }catch (SQLException e) { } //insert 3 rows of data try { stmt = conn.createStatement(); stmt.executeUpdate("insert into foo values (1,0)"); stmt.executeUpdate("insert into foo values (2,1)"); stmt.executeUpdate("insert into foo values (3,0)"); }catch (SQLException e) { } //now retrive all three rows then update value equals 1 to 2; //this works for mysql-connector-3.0.9 but not 5.1.12 sqlStmt="select * from foo"; try { stmt = conn.createStatement(); rs = stmt.executeQuery(sqlStmt); int count=0; while (rs.next()) { // <-- It fails here for 5.1.12 String value=rs.getString("value"); if (value.equals("1")) { sqlStmt="update foo set value=2 " +"where value=1 " ; stmt.executeUpdate(sqlStmt); System.out.println("****:"+(count++)); } } }catch (SQLException e) { e.printStackTrace(System.out); } } }