java可以创建组合框方法吗
这是我想在各种组合框上执行的代码块
重要信息:
AssignRollno()
是我创建的一个方法,它返回一个int值,并按照它所说的那样为新用户分配一个rollno。字符串“a”是用户的名称。方法execute()
执行mySQL
中的字符串
问题:
现在,有一些组合框命名为d1 d2 d3。。。。。d8。我不想把整个代码写8次,而是想写一次,让它在所有组合框中执行。如果可能的话。所以,我想像for循环一样执行它(显然for循环不允许我这样做)
在下面的代码中,我只希望“x”将增量保持在1到8之间,并执行代码块8次 有没有办法做到这一点
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);
}
# 1 楼答案
我不太确定你到底想要什么。但您可以为组合框使用数组:
# 2 楼答案
用逗号怎么样
范例
插入到dx值中
问题重复Inserting multiple rows in mysql