I created a query to get the required data but have failed to get the JTable
to populate. The table just appears empty.
Essentially, I want to get an ID from one JFrame
click a button, and open another frame that contains a table connected to the database but now only have it display data related to that ID instead of all the data in that database.
Is there another way I could execute what I want to do?
Update: Managed to figure it out, turns out it was the if statement messing with my rs.next()
value causing the while statement not to execute and the lack of columns added to the model for the values to be populated under.
FamilyProfile one = new FamilyProfile();
String query ="SELECT * FROM `family_db` WHERE Parent_ID=?";
try {
ps = db_connect.prepareStatement(query);
ps.setString(1, famID);
rs = ps.executeQuery();
DefaultTableModel model = (DefaultTableModel) one.Famtbl.getModel();
model.addColumn("Family_ID");
model.addColumn("Family_Name");
model.addColumn("Parent_ID");
model.addColumn("Child_ID");
while(rs.next())
{
String n = rs.getString("Family_ID");
String e= rs.getString("Family_Name");
String r= rs.getString("Parent_ID");
String d= rs.getString("Child_ID");
// This will add row from the DB as the last row in the JTable.
//model.addRow(new Object[] {n, e, r, d});
model.insertRow(one.Famtbl.getRowCount(), new Object[] {n, e, r, d});
}
one.setVisible(true);