This is a block of code which I want to execute on various Combo Boxes
Important Information:
AssignRollno()
is a method which i created which returns a int value and as it says it assigns a rollno to the new user. String 'a' is the name of the user. The method execute()
executes the string in mySQL
.
Problem:
Now, there are Combo Boxes named as d1 d2 d3 ..... d8. Instead of writing the whole code 8 times I want to write it once and make it execute for all the Combo Boxes. If possible. So, I want to execute it like a for a loop ( obviously a for loop would not let me do it ).
In the following code i just want 'x' to keep increment from 1 to 8 and execute the block of code 8 times Is there any way to do that ??
String a=t1.getText();
int i=AssignRollno();
int j=dx.getSelectedIndex();
if(j==0)
{
String str1="insert into dx values("+i+",'"+a+"')";
execute(str1);
String str2="insert into t"+i+"1"+" values(0)";
execute(str2);
}
else
{
String str3="insert into t"+i+"1 values("+j+")";
execute(str3);
}