java使用for循环在从数据库获取的jTextFields中设置值
我想执行一个查询并将这些值添加到循环中的文本字段中。我想要这样的东西
String query = "select student_id,String firstName,lastName,address,phoneNumber,mobileNumber,fathersName,fathersOccupation,mothersName,nationality,qualification from student where student_id='" + jTextField5.getText().toString() + "'";
ResultSet rs = DBOptions.executeSQLQuery(query);
rs.next();
for(int i=0; i < 11; i++){
String s = rs.getString(i+1);
String field = "jTextField"+i+".setText(s)";//can you do something like this and use the string to add values to individual textFeilds?
}
我试过用ArrayList和其他方法查看,但它们似乎令人困惑
# 1 楼答案
将所有
jtextField
存储在ArrayList
中,但确保它们是按顺序插入的那么你的方法呢