Here is a section of code from a MODEL class of the MVC Framework:
public TableModel getTableData() throws SQLException {
try {
String sql = "SELECT date as 'Date',eventName as 'Name', time as 'Start Time' FROM Event";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
TableModel model = (DbUtils.resultSetToTableModel(rs));
return model;
}
finally {
try {rs.close(); pst.close(); conn.close(); }
catch(SQLException e){}
}
}
I am struggling to get the model of the table and set it to table in VIEW class where my only error seems to be java.sql exception not being caught or thrown. I don't want to be doing this in VIEW class as it is a bad practice. ideally should be done in MODEL. Here is the proportion of the code from VIEW I'm struggling to deal with;
/*Constructor*/
public EventView() {
initComponents();
this.model = new EventModel();
tableEvent.setModel(model.getTableData());
}
How do I adjust my code and set up the table on initialisation appropriately without handing errors on interface, i.e. VIEW Class