I am trying to store the time into a database when a user logs-off or logs-in into the computer but when I logs my computer off it does not store my current time into the database where if I press ctrl+c
on console or terminate the program from NETBEANS it stores the logout time too. Where am I doing it wrong ? Please help me out with this. Below is my code. Thank you in advance.
public void logoutTime() throws Exception {
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
SimpleDateFormat sdf1 = new SimpleDateFormat("HH:mm:ss");
String time = String.format(sdf1.format(calendar.getTime()));
Globals.globalClockBean.setLogout_time(time);
try {
cd.insert(Globals.globalClockBean);
} catch (Exception ex) {
Logger.getLogger(ClockController.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Closing: Logged out at yayyyyyyyyy: " + time);
System.out.println(sdf1.format(calendar.getTime()));
}
}));