Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
    Bookmark Topic Watch Topic
  • New Topic

Vector of Vectors trouble

 
Padraig Joseph
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Report post to moderator
I'm having problems with the code below. Everything goes fine until I try to add vctTemp to vctFootballRecord. Instead of just appending the new vector element to the end of the vector, it seems to replace every existing element in the vector with the new one as well. What's going on?
String football = "SELECT * FROM tblGAAFootball WHERE year >= 1997";
try{
statement = connection.createStatement();
resultSetF = statement.executeQuery(football);
while (resultSetF.next()) {
vctFootballList.removeAllElements();
vctTemp.removeAllElements();
String nDateF = resultSetF.getString("date");
vctFootballList.addElement(nDateF);
String nMonthF = resultSetF.getString("month");
vctFootballList.addElement(nMonthF);
String nYearF = resultSetF.getString("year");
vctFootballList.addElement(nYearF);
String szTeam1F = resultSetF.getString("team1");
vctFootballList.addElement(szTeam1F);
String szTeam2F = resultSetF.getString("team2");
vctFootballList.addElement(szTeam2F);
String nTeam1GoalsF = resultSetF.getString("team1Goals");
vctFootballList.addElement(nTeam1GoalsF);
String nTeam1PointsF = resultSetF.getString("team1Points");
vctFootballList.addElement(nTeam1PointsF);
String nTeam2GoalsF = resultSetF.getString("team2Goals");
vctFootballList.addElement(nTeam2GoalsF);
String nTeam2PointsF = resultSetF.getString("team2Points");
vctFootballList.addElement(nTeam2PointsF);
String szNeutralF = resultSetF.getString("neutral");
vctFootballList.addElement(szNeutralF);
String szCompetitionF = resultSetF.getString("competition");
vctFootballList.addElement(szCompetitionF);
String szStageF = resultSetF.getString("stage");
vctFootballList.addElement(szStageF);
for(int i=0; i<12; i++)
{
vctTemp.addElement(vctFootballList.elementAt(i));
}

vctFootballRecord.add(vctTemp);
}
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't cross post, it just makes it difficult to follow a conversation. Now, back in the beginners forum...
 
    Bookmark Topic Watch Topic
  • New Topic