These three line of code are have to be execute at the same time.
SET @num := 0;
UPDATE your_table SET id = @num := (@num+1);
ALTER TABLE tableName AUTO_INCREMENT = 1;
********************************************************
Statement s1 = DataCon.getDataCon().createStatement();
s1.execute("SET @num := 0; UPDATE tblstaff SET staffid = @num := (@num+1); ALTER TABLE tblstaff AUTO_INCREMENT = 1");
s1.close();