Q: Fill JTable from database I write this simple code to fill jTable1, but it just fills jTable1 with the last row from the database.
String SQL = "select * from usernames";
ResultSet rs = stmt.executeQuery(SQL);
String[] columnNames = {"Full Name", "Email"}; 
String n = "",e = "";
while(rs.next()) { 
    n = rs.getString("Full_Name");
    e = rs.getString("Email");
    Object[][]data = {{n,e}}; 
    jTable1 = new JTable(data, columnNames);

}       


A: I solved it by this code
String n = "",e = "";      

DefaultTableModel model;
model = new DefaultTableModel(); 
jTable1 = new  JTable(model);

model.addColumn("Full Name");
model.addColumn("Email");

while(rs.next())  
{
    n = rs.getString("Full_Name");    
    e= rs.getString("Email");   
    model.addRow(new Object[]{n,e});
}


A: Yes, it will always be the last row since in the while loop you are creating a new JTable instead of appending a row to the existing one. So do like this,
// Code
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
while(rs.next())
{ 
    n = rs.getString("Full_Name");
    e= rs.getString("Email");
    //Object[][]data={{n,e}};
    // This will add row from the DB as the last row in the JTable. 
    model.insertRow(jtable1.getRowCount(), new Object[] {n, e});
}       

