Hello everybody, I face a problem in using AbstractTableModel, i use linked list as a container for data , and i fetch records from table from db then i put it in linked list in table model then i male jable.setModel(model). THE PROBLEM i face that the last record i fetch from table from db is repeated n times since n is the number of records in database. and when i make model.getIndextOF(anAppointmentDate); each time return 0 , so i think it each time the object in inserted in the same place ? i may be wrong , but that what i think public class appointmentModel extends AbstractTableModel {
List<appointmentDate> patientAppointment;
public appointmentModel() {
patientAppointment = new LinkedList<appointmentDate>(); // linked list
}
public int getRowCount() {
return patientAppointment.size();
}
public int getColumnCount() {
return 2;
}
public String getValueAt(int rowIndex, int columnIndex) {
if (columnIndex == 0) {
return patientAppointment.get(rowIndex).getDateOFAppointment();
} else if (columnIndex == 1) {
return patientAppointment.get(rowIndex).getTimeOfAppointment();
} else {
return "Not found";
}
}
public String getColumnName(int column) {
if (column == 0) {
return "date";
} else if (column == 1) {
return "time";
} else {
return "not found";
}
}
public void insertRecord(appointmentDate anAppointmentDate)
{
list.add(anAppointmentDate);
fireTableRowsInserted(list.size()-1, list.size()-1);
System.out.println(list.indexOf(anAppointmentDate)); // each time it prints 0
}
////////// here where i use the model
while (resultSet.next()) {
N_Date= resultSet.getDate("appointDate");
anAppointment.setDateOFAppointment(N_Date);
N_time = resultSet.getString("appointTime");
anAppointment.setTimeOfAppointment(N_time);
tableModel.insertRecord(anAppointment);
}
jTable.setModel(tableModel);
The output i have is the last record repeated in all table records ,plz help!