当用户注销或登录计算机时,我试图将时间存储到数据库中,但是当我注销计算机时,它不会将当前时间存储到数据库中,如果我按下ctrl+c
控制台或终止程序从 NETBEANS 它也存储注销时间。我在哪里做错了?这个你能帮我吗。下面是我的代码。先感谢您。
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()));
}
}));