I am trying To display the content of the table selected(Imported from MySql) in a JTable whose Structure is unknown to me . I Have Successfully added columns in Jtable but not Able to add rows which the ResultSet Object Returns. Please Help me Insert The Row DATA . I am Attaching the Code.
private void btnDisplayTableContentActionPerformed(java.awt.event.ActionEvent evt) {
try
{ String selTN=cmbTable.getSelectedItem().toString();
String r="select*from "+selTN;
TableRecords= stmt.executeQuery(r);//TableRecords is a resultset object
rsmd=TableRecords.getMetaData();//rsmd is a Resultsetmetadata object
int n = rsmd.getColumnCount();// column no starts from 1
DefaultTableModel model=(DefaultTableModel)tblDisplay.getModel();
int i = 1;
while(i<=n){
model.addColumn(rsmd.getColumnName(i));// columns suceesfully added
i++;
}
while(TableRecords.next())
{ int k =1;
//Unable to add rows Please help
}
tblDisplay.setModel(model);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
}