'JTable records not displayed
I am trying to display the records on JTable when the frame is loaded, but the records didn't display. This is what I've tried so far:
public void load() {
try {
Connection con1;
PreparedStatement insert;
Class.forName("com.mysql.jdbc.Driver");
con1 = DriverManager.getConnection("jdbc:mysql://localhost/javapos","root","");
insert = con1.prepareStatement("SELECT name,status FROM category");
ResultSet Rs = insert.executeQuery();
while(Rs.next()) {
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
String name = Rs.getString("name");
String status = Rs.getString("status");
model.addRow(new Object[]{name,status });
}
jTable1.setModel(model);
} catch (Exception e) {
System.out.println("Failed " + e);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
