I want to sort the adding array in the code block below according to the integer value workinghour, but I get the information from mySQL and I need to display it in JTable. How can I sort?
public void monthOfEmployee() {
model.setRowCount(0);
ArrayList<Employee> employees = new ArrayList<Employee>();
employees = process.showEmployee();
if (employees != null) {
for (Employee employee : employees) {
Object[] adding = { employee.getID(), employee.getName(), employee.getSalary(),
employee.getWorkingHour() };
model.addRow(adding);
}
}
}
SQL query
public ArrayList<Employee> showEmployee() {
ArrayList<Employee> tried = new ArrayList<Employee>();
try {
statement = con.createStatement();
String query = "Select * From employee";
ResultSet rs = statement.executeQuery(query);
while (rs.next()) {
String iD = rs.getString("emp_ID");
int workingHour = rs.getInt("working_hour");
int salary = rs.getInt("salary");
String name = rs.getString("emp_name");
tried.add(new Employee(name, iD, salary, workingHour));
}
return tried;
} catch (SQLException ex) {
Logger.getLogger(Process.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}