很抱歉我的问题很严重,但是我在一个类中有这个ArrayList,我从另一个层的main / menu类运行,但我只是认为你需要看到这段代码才能帮助我。 下面我有两个输出:第一个显示这个ArrayList打印出来的内容 第二个显示了我想要它的样子。 我在ArrayList中有什么变化?
请记住,我正在使用三层架构
public ArrayList<BEGroup> getGroupRankings() throws SQLException {
ArrayList<BEGroup> result = new ArrayList<>();
Statement stm2 = mConnection.createStatement();;
stm2.execute("select * from [Group]");
ResultSet res = stm2.getResultSet();
int id = 0;
while (res.next()) {
System.out.println(res.getString("GroupName"));
++id;
Statement stm = mConnection.createStatement();
stm.execute("Select Team.School, MatchesPlayed, (GoalsFor-GoalsAgainst) as [Goal Difference], "
+ "Points from GroupStandings INNER JOIN Team on Team.id = GroupStandings.TeamID "
+ "where GroupStandings.GroupID = " + id + " "
+ "order by GroupStandings.GroupID, Points desc, [Goal Difference] desc, GoalsFor desc ");
ResultSet res2 = stm.getResultSet();
while (res2.next()){
String school = res2.getString("School");
int matchesPlayed = res2.getInt("MatchesPlayed");
int goalDifference = res2.getInt("Goal Difference");
int points = res2.getInt("Points");
result.add(new BEGroup(school, matchesPlayed, goalDifference, points));
}
}
return result;
}
输出如下所示:希望它看起来像这样:
Group A Group A
Group B School 1: 0 2 33
School 1: 0 2 33 School 2: 7 -3 7
School 2: 7 -3 7 Group B
School 3: 3 4 3 School 3: 3 4 3
School 4: 2 3 2 School 4: 2 3 2
编辑:另外,如果我把返回结果;就在当前的回报结果之上;在结尾,我几乎得到它(只有A组,而不是其他组):
输出:
Group Rankings:
Group A
School 1: 0 2 33
School 2: 7 -3 7
School 3: 3 4 3
School 4: 2 3 2