Hi I have successfully linked my jTable to JDBC database. However, I am having trouble retrieving them. I want the saved data to appear when I restart the program but it is
Start by creating a new TableModel
...
DefaultTableModel model = new DefaultTableModel(new String[]{"Class Name", "Home work", "Due Date"}, 0);
Load the data from the database...
String sql="SELECT * FROM hwList";
ResultSet rs = st.executeQuery(sql);
Add each row of data to the table model...
while(rs.next())
{
String d = rs.getString("className");
String e = rs.getString("homeWork");
String f = rs.getString("dueDate");
model.addRow(new Object[]{d, e, f});
}
Apply the model to your JTable
...
table.setModel(model);
You may also want to look at The try-with-resources Statement and make sure you're managing your resources properly