Hi everyone
I am making a system where i have to refresh the database after updating it. I am using a JTable and a mysql database, but i have to close down the application so that the updates can be implemented.Is there a way of refreshing the connection session, or refreshing an entitymanager at real time rather than closing it down first?
Please Help Guys.

6 Years
Discussion Span
Last Post by JoshuaKissoon

Hi joe_ojah,

Have you try fireTableDataChanged(); and

class TableListener implements TableModelListener {
        public void tableChanged(TableModelEvent e) {
            for (int i=0; i< getRowCount(); i++) {
                for (int j=0; j< getColumnCount()-1; j++)
                    System.out.print(getValueAt(i, j) + "\t");

or you have to do separated function which download vector. Do you use a vector or similar?


Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)


hey i dont know how well u know to program in java. but it is advisible to use a vector or an Arraylist to grab the data from the database, then populate the JTable from the vector;
you can use a function:

private ArrayList getInformation()
   ArrayList<String> arraylist = null;
   resultSet = "query";
      // Declaring A Vector to hold that row of information
      Vector<String> vector = new Vector<String>;
      vector.add(resultSet.getString("Whatever")); //a field (say firstName)
      vector.add(resultSet.getString("Whatever")); // another field (say lastName)
      vector.add(resultSet.getString("Whatever")); // another field(say DOB)
      // adding that vector as a row in the arraylist

   return arrayList;

to populate the JTable(Say in another class), use:

ArrayList<String> arrayList = getInformation();
JTable table = new JTable();
table.setModel(new defaultTableModel(arrayList.toString);

and to refresh the table:
in your actionPerformed method:
just repopulate the arrayList : ArrayList<String> arrayList = getInformation(); then reset the table Model: table.setModel(new defaultTableModel(arrayList.toString); NOTE: the table and arraylist has to be public to that class

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.