2014-12-24 79 views
-1

在我的查詢我要存儲在B變量的當前系統時間,使我可以與其他的時間來執行以下條件變量比較。請幫我在我的編碼..儲存時間變

 ResultSet rs=stmt.executeQuery(sql); 

     String user=txtid.getText(); 
     String pwd=new String (passwordfld.getPassword()); 
     int loop=0; 
     while(rs.next()) 
     { 
      String uname=rs.getString("Emp_ID"); 
      String password=rs.getString("Password"); 
      if ((user.equals(uname)) && (pwd.equals(password))) 
      { 
       st.executeUpdate("insert into Attendance (Emp_ID,Date,Time_in) Values ('"+user+"',curdate(),curtime());"); 


       s.executeUpdate("update Attendance set Late='Yes' where emp_id='"+user+"' and date=curdate() and time_in>'23:15:00';"); 
       s.executeUpdate("update Attendance set Late='No' where emp_id='"+user+"' and date=curdate() and time_in<'23:15:00';"); 


       Time b=new Time(); 


       if (b>08:40:00) 
       { 
        s.executeUpdate("update Attendance set Late='Yes' where emp_id='"+user+"' and date=curdate();"); 
        JOptionPane.showMessageDialog(null, "OOps You are late..!!"); 
       } 
       else 
       { 
        s.executeUpdate("update Attendance set Late='No' where emp_id='"+user+"' and date=curdate();"); 
       } 

       JOptionPane.showMessageDialog(null, "HAve a niCe daY"); 
       dispose(); 
       new Home().setVisible(true); 
       loop++; 
      } 
     } 
     rs.close(); 
     if (loop==0) { 
      JOptionPane.showMessageDialog(null, "Username and Password not in database!"); 
     } 
    } 
    catch (Exception e) 
    { 
     JOptionPane.showMessageDialog(null,e); 
}         
+0

請看看'PreparedStatement'保存自己從'SQL injection'。 –

+1

請包含您的表架構,以及在表格中使用日期和時間的示例值 – janos

+0

您可以使用'java.util.Date'變量。 –

回答

1

你可以嘗試這樣的:

Calendar c = Calendar.getInstance(); 
if (c.get(Calendar.HOUR_OF_DAY) >= 8 && c.get(Calendar.MINUTE) >= 40) {//if you want 8PM then replace 8 with 20. 
    System.out.println("Hello time now is greater than 8:40AM"); 
} 
+0

謝謝你的幫助 –