dimanche 24 mai 2015

Java If esle Condition else statement not working properly

in payroll system i want to change the calculation method for the holidays. in that i get holidays dates from the database. but when i run the while & for loop with if else condition IF condition work properly but when its go to else that show all data in dates in database. not filter with holidays `

private void CheckHolidays() {
    DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
    String holiday = null;
          String nonholiday = null;
    try {
    ResultSet r = (ResultSet) DB.query("SELECT * FROM holidays order     by holidaysList");

    while (r.next()) {
            holiday = r.getString("holidaysList");

            for (int i = 0; i < jTable1.getRowCount(); i++) {
                String tableDate = (String) (dtm.getValueAt(i, 1));
                if (holiday.equals(tableDate)) {

                    System.out.println("Holiday     User -" + (dtm.getValueAt(i, 0))+"  Date  "+ (dtm.getValueAt(i, 1)));

                } else if  (!(holiday.equals(tableDate)) ) {

                    System.out.println("NOTT HOLIDAY      User -" + (dtm.getValueAt(i, 0)));

                }

            }
        }
    } catch (Exception ex) {
        Logger.getLogger(sync_data1.class.getName()).log(Level.SEVERE, null, ex);
    }
}`

Output is

Holiday     User -d  Date  23-03-2015
NOTT HOLIDAY      User -a
NOTT HOLIDAY      User -b
NOTT HOLIDAY      User -e
NOTT HOLIDAY      User -c
NOTT HOLIDAY      User -d
NOTT HOLIDAY      User -a
NOTT HOLIDAY      User -b
NOTT HOLIDAY      User -e
Holiday     User -c  Date  26-03-2015

26/03/2015 & 23/03/2015 are holidays those 2 days filter correctly in IF condition but when its go to ELSE it show all

if code is correct this is the output i need

Holiday     User -d  Date  23-03-2015
NOTT HOLIDAY      User -a
NOTT HOLIDAY      User -b
NOTT HOLIDAY      User -e
Holiday     User -c  Date  26-03-2015

Aucun commentaire:

Enregistrer un commentaire