title: How to update(refresh) JTable with data from a database
body: <p>I'm trying to update a <code>JTable</code> after I add or remove a record from the database (MS Access), but it doesn't seem to work.  Also, I don't understand why my column names do not show up. Here's my code:</p>
  
  <pre><code>package Administrator13_03_13;
  
  public class Arsti2 {
  JFrame main = new JFrame("Ārst");
  JPanel tP = new JPanel();
  JPanel bP = new JPanel();
  JButton one = new JButton("Test");
  JTable table = new JTable();
  DefaultTableModel model;
  Vector columnNames = new Vector();
  Vector data = new Vector();
  
  Arsti2() {
      main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      main.setSize(840,300);
      try {
  
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          String Base = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; DBQ=SL.mdb";
          Connection con = DriverManager.getConnection(Base,"","");
          Statement st = con.createStatement();
          ResultSet res = st.executeQuery("SELECT * FROM Arsti");
          ResultSetMetaData rsmd = res.getMetaData();
          int column = rsmd.getColumnCount();         
          columnNames.addElement("ID");
          columnNames.addElement("Vards");
          columnNames.addElement("Uzvards");
          columnNames.addElement("Dzimums");
          columnNames.addElement("Personas kods");
          columnNames.addElement("Telefona numurs");
          columnNames.addElement("Nodalas ID");
          columnNames.addElement("Amata ID");
          while(res.next()) {
              Vector row = new Vector(column);
              for(int i=1; i&lt;=column; i++) {
                  row.addElement(res.getObject(i));
              }
              data.addElement(row);
          }
          model = new DefaultTableModel(data,columnNames);
          table.setModel(model);
          //model.fireTableDataChanged();
          tP.add(table);
          bP.add(one);
          main.add(tP,BorderLayout.NORTH);
          main.add(bP,BorderLayout.SOUTH);
      } catch(Exception e) {
          e.printStackTrace();
      }
      main.setVisible(true);
      one.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent evnt1) {
              model.fireTableDataChanged();
          }
      });
  }
  
  public static void main(String[] args) {
      new Arsti2();
  }
  }
  </code></pre>