title: Implementing AbstractTableModel to JTable. How to add the methods?
body: <p>I used to display my database data in a JTable and it was working fine. I found out that I need to implement AbstractTableModel or DefaultTableModel to update the data instantly. </p>
  
  <p>I am not sure what I should write in getValueAt()? Where should I add fireDataChanged()? Any guidance is appreciated, thanks!    </p>
  
  <p>I used to retrieve my database data with this code: </p>
  
  <pre><code>Vector columnNames = new Vector();
  Vector data = new Vector();  
  
  try
  {
      Class.forName("com.mysql.jdbc.Driver");
      Connection con = DriverManager.getConnection ("jdbc:mysql://localhost:3306/watchlist","root","root");                   
  
      String sql = "SELECT * FROM watchlist";
      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery(sql);
      ResultSetMetaData md = rs.getMetaData();
  
      int columns = md.getColumnCount();
      for (int i = 1; i &lt;= columns; i++)
      {
          columnNames.addElement( md.getColumnName(i));
      }                               
  
      int rowCount = md.getColumnCount();             
      while (rs.next())
      {
          Vector row = new Vector(rowCount);
  
          for (int i=1; i &lt;= rowCount; i++)
          {
              row.addElement( rs.getObject(i) );
          }
  
          data.addElement( row );
      }
  
      rs.close();
      stmt.close();
      con.close();                                      
  }
  
  catch(Exception e)
  {
      System.out.println(e);
  } 
  </code></pre>
  
  <p>My AbstractTableModel:</p>
  
  <pre><code>public class MyTableModel extends AbstractTableModel 
  {
      Vector columnNames = new Vector(); 
      Vector data = new Vector(); 
  
      public void connectionDB()
      {
          try
          {                               
              Class.forName("com.mysql.jdbc.Driver");
              Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/watchlist","root","root");
  
               String sql = "SELECT * FROM watchlist";
               Statement stmt = con.createStatement();
               ResultSet rs = stmt.executeQuery(sql);
               ResultSetMetaData md = rs.getMetaData();   
          }
  
          catch(Exception e)
          {
              System.out.println(e);
          }
      }
  
      public int getColumnCount() 
      {
          return columnNames.size(); 
      }
  
      public int getRowCount() 
      {
          return data.size(); 
      }
  
      public Object getValueAt()
      {
          return data;    
      }
  
      public boolean isCellEditable(int row, int col)
      {
          return false; 
      }
  
  }
  </code></pre>