title: Displaying data from JDBC into a JTable
body: <p>I've followed some previous advice on this site about displaying database information in tables, however mine still won't work. I have a generated Netbeans Dialog with a table named mainTable, I am setting the Model to a ResultSet that has been taken from the MySql.</p>
  
  <p><strong>EDIT the entire class:</strong></p>
  
  <pre><code>import swing.SwingUtilities;
  import javax.java.awt.Dialog;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.sql.ResultSet;
  import java.sql.ResultSetMetaData;
  import java.sql.SQLException;
  import java.util.Vector;
  
  import javax.swing.JDialog;
  import javax.swing.JOptionPane;
  
  swing.table.DefaultTableModel;
  
  public class AddressBookImpl extends AddressBookGui implements ActionListener {
  final static AddressBookImpl impl = new AddressBookImpl();
  DefaultTableModel defaultTableModel = new DefaultTableModel();
  AddressBookGui gui = new AddressBookGui();
  
  
  
  public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
          @Override public void run() { impl.startGUI(); }});
  }
  
  public void startGUI(){
      gui.main(null);
      setDefaultCloseOperation(DISPOSE_ON_CLOSE);
      this.setResizable(true);
      this.setTitle("Address Book");
      listeners();
      refreshTable();
  }
  
  public DefaultTableModel refreshTable() {
      try{
  
          DatabaseImpl dbimpl = new DatabaseImpl();
          dbimpl.refreshDatabase();
          ResultSet refreshResult = dbimpl.refreshResult;
          ResultSetMetaData meta = refreshResult.getMetaData();
          int numberOfColumns = meta.getColumnCount();
  
          while (refreshResult.next()) 
          {
              Object[] rowData = new Object[numberOfColumns];
  
              for (int i = 0; i &lt; rowData.length; ++i)
              {
                  rowData[i] = refreshResult.getObject(i + 1);
              }
              defaultTableModel.addRow(rowData);
          }
          this.defaultTableModel = defaultTableModel;
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      gui.mainTable.setModel(defaultTableModel);
      return defaultTableModel;
  }
  
  
  public void listeners() {
      quitFileMenuBar.addActionListener(this);
      addButton.addActionListener(this);
      refreshButton.addActionListener(this);
  }
  
  @Override
  public void actionPerformed(ActionEvent e) {
      if (e.getActionCommand().equalsIgnoreCase("Quit")) 
      {
          this.dispose();
      }
      if (e.getActionCommand().equalsIgnoreCase("Add"))
      {
          // Add a new address to the DB
      }
      if (e.getActionCommand().equalsIgnoreCase("About"))
      {
  
      }
      if (e.getActionCommand().equalsIgnoreCase("Refresh"))
      {
          refreshTable();
          System.out.println("Refreshing........");
      }
  }
  }
  </code></pre>
  
  <p>And the DatabaseImpl class:</p>
  
  <pre><code>protected ResultSet refreshDatabase() {
      try {
          Class.forName("com.mysql.jdbc.Driver");
          con = DriverManager.getConnection(url, user, password);
          System.out.println("Connection is created to " + url);
  
          Statement statement = con.createStatement();
          String selectAllQuery = "Select * from " + table + ";";
  
          ResultSet refreshResult = statement.executeQuery(selectAllQuery);
  //          con.close();
          this.refreshResult = refreshResult;
          return refreshResult;
  
      } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (ClassNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      return refreshResult;
  }
  </code></pre>
  
  <p>However this just shows a blank area where the table should be, any help?</p>
  
  <p>The GUI class is a bog standard netbeans generated class.</p>