I' working on a hotel management software and wants the numbers of days a present guest have stayed to show on a JTable on
clicking a Button that is meant to select all guestid and NoOfDays in a table I named InGuests .e.g "SELECT GUESTID, NOOFDAYS
FROM INGUESTS".
I retrieved with ResultSet and used while loop to iterate on the result and compare the current date with the date checked in.
I also made it to increement or void where necessary and finally update the NoOfDays column in the InGuests Table. but it seems not tot be working. Please help me
If you don't understand...kindly ask me to explain more.
Thanks Gurus in da house
// get the current system date Date dated = new Date(); //returns only the date String date = DateFormat.getDateInstance().format(dated); String mo = ""; String da = ""; String yy = ""; StringTokenizer tok = new StringTokenizer(date, " "); if(date != null) { mo = tok.nextToken().toString(); da = tok.nextToken().toString(); yy = tok.nextToken().toString(); } String day = ""; String month = ""; String year = ""; if(mo.equalsIgnoreCase("Jan")) { month = "01"; } else if(mo.equalsIgnoreCase("Feb")) { month = "02"; } else if(mo.equalsIgnoreCase("Mar")) { month = "03"; } else if(mo.startsWith("Apr")) { month = "04"; } else if(mo.equalsIgnoreCase("May")) { month = "05"; } else if(mo.equalsIgnoreCase("Jun")) { month = "06"; } else if(mo.equalsIgnoreCase("Jul")) { month = "07"; } else if(mo.startsWith("Aug")) { month = "08"; } else if(mo.startsWith("Sept")) { month = "09"; } else if(mo.equalsIgnoreCase("Oct")) { month = "10"; } else if(mo.equalsIgnoreCase("Nov")) { month = "11"; } else if(mo.equalsIgnoreCase("Dec")) { month = "12"; } String currDate = da.substring(0,2)+"/"+month+"/"+yy; StringTokenizer currDateToken = new StringTokenizer(currDate, "/"); if(currDate != null) { toDay = currDateToken.nextToken().toString(); todayMonth = currDateToken.nextToken().toString(); todayYear = currDateToken.nextToken().toString(); } int curr = 0; int inDate = Integer.parseInt(InDa); int toDate = Integer.parseInt(toDay); if(toDate != inDate) { NoOfDays++; NoOfDays = curr; } else if(inDate == toDate) { NoOfDays = curr; } try { String updateDays = "update inguests set Noofdays = '"+NoOfDays+"' where guestid = '"+id+"'"; int up = Database.exec(updateDays); if(up >= 1) { initLabel.setText("InGuests Initialized!"); } else { initLabel.setText("InGuests not Initialized!"); } } catch(Exception ex) { ex.printStackTrace(); }