我試圖將表中的行存儲到數組中。我可以得到第一個結果並存儲,但我似乎無法存儲任何其他數據。將MySQL表中的行存儲到Java中的數組中
這是代碼我已經寫
try
{
test = "select * from Arsenal order by 'MatchNumber' ASC";
rs = st.executeQuery(test);
while (rs.next())
{
//This retrieves each row of Arsenal table and adds it to an array in the Team Results class.
matchno = rs.getString("MatchNumber");
hometeam = rs.getString("HomeTeam");
awayteam = rs.getString("AwayTeam");
homegoals = rs.getString("HomeGoals");
awaygoals = rs.getString("AwayGoals");
result = rs.getString("Result");
teams = (matchno + "," + hometeam + "," + awayteam + "," + homegoals + "," + awaygoals + "," + result); // Takes all the variables containging a single customers information and puts it into a string, seperated by commas.
TeamResults.add(matchno,hometeam,awayteam,homegoals,awaygoals,result);
}
}
任何想法,我要去哪裏錯了嗎?
這是完全錯誤的,'next()'負責移動光標從當前位置移動一行,所以他不需要改變它,也沒有在'ResultSet中有'hasNext()'方法可用'類 – Salah
是的,就像我寫的一樣。 – Smutje
你是什麼意思? – user3139748