Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 933337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:49:09+00:00 2026-05-15T20:49:09+00:00

I face a problem in using AbstractTableModel, i use linked list as a container

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:49:10+00:00Added an answer on May 15, 2026 at 8:49 pm

    You are using the same reference to an AppointmentDate object, and change only its internal state.

    Thus everytime you add the same object to the list. So with the last loop iteration you set all objects inside the list to have the data of the last row.

    To fix this, instantiate a new AppointmentDate() on each loop iteration:

    while (resultSet.next()) {
        AppointmentDate anAppointment = new AppontmentDate();
        // the rest is the same
    }
    

    Note also that the class name should start with an upper-case letter – i.e. AppointmentDate, not appointmentDate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 515k
  • Answers 515k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Moving the static content(javascript, css, images) to a 3rd part… May 16, 2026 at 6:31 pm
  • Editorial Team
    Editorial Team added an answer The interesting ones are in deploy/messaging/jms-ds.xml java:/JmsXA - "use this… May 16, 2026 at 6:31 pm
  • Editorial Team
    Editorial Team added an answer http://ocaoimh.ie/wp-super-cache-developers/ says:Clearing the Cache The development version of the plugin… May 16, 2026 at 6:31 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I face the following strange problem while using JFileChooser package sandbox; import java.io.File; import
I face a problem when using QueryElevation . I want to split the elevation
I often face the problem of wanting to add additional methods to classes I
i'm building a site where we are considering to use a custom font (using
I've been using headers to create templates for websites. It's easy, and very convenient
The problem we have now in your development process, is that there are a
I have some problem with replace string in Ruby. My Original string : What
Currently, I'm trying to develop a rich internet application using Flash Builder 4 Beta
I want to add scripting support for an Objective-C project using the objc runtime.
I am working on ASP.Net 2.0 website and I have a strange problem. First

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.