I'm trying to cycle through a series of dynamic fields and update the value to the database. But the value of the last field is the one retrived and updated to all fields in the loop. How do i solve this problem. Thank you so so much for your help.
rst2 = stm1.executeQuery("select * from students");
String subject = request.getParameter("subject");
for(int i = 0; rst2.next(); i++){
String ca1 = request.getParameter("ca1_"+i);
String sa1 = request.getParameter("sa1_"+i);
String ca2 = request.getParameter("ca2_"+i);
String sa2 = request.getParameter("sa2_"+i);
//String query2 = "INSERT into results(ca1,sa1,ca2,sa2) values ('"+ca1+"','"+sa1+"','"+ca2+"','"+sa2+"')";
stm2.executeUpdate("UPDATE results SET ca1 ='"+ca1+"', sa1 ='"+sa1+"', ca2 ='"+ca2+"', sa2 ='"+sa2+"' where subject like '" + subject + "%'");
}