0

I'm developing a fingerprint based attendance system using Java and i don't know how to automatically logout after the 2nd time around of scanning the same fingerprint data. The question is how to minus the current time and the time that has been stored in the database.

here is my code

  String sqlReports ="SELECT 
  sch_id='"+id.getText()+"',name,date,timein,timeout FROM reports";
  Statement st = cn.createStatement();
  ResultSet rs = st.executeQuery(sqlReports);              
  while(rs.next()){
  SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); 
  out.setText(sdf.format(rs.getString("timeout")));
  String r= sdf.format(cal.getTime());

if (cal.getTime() - out.getText() > 10) {

//Updatesqlhere

        }`
ar1020
  • 1
  • 1
  • 1
    What are you asking about here? How to do time calculations or...? Please add the code that is causing the issue so we get some more context. – Joakim Danielson Jan 24 '19 at 15:04
  • I am not sure what exactly you mean by fingerprint data. Can you specify how you get the current time and the time stamp from your data? Is it UTC? What is the format? What have you tried and found so far? – LinFelix Jan 24 '19 at 15:04
  • 1
    What's the database table structure? And in Java, do you have a `java.util.Date`? – The Impaler Jan 24 '19 at 15:05
  • 1
    What's the database engine? DB2, PostgreSQL, Informix, etc. – The Impaler Jan 24 '19 at 15:06
  • here is my code : and i'm getting error – ar1020 Jan 24 '19 at 15:12
  • String sqlReports ="SELECT sch_id='"+id.getText()+"',name,date,timein,timeout FROM reports"; Statement st = cn.createStatement(); ResultSet rs = st.executeQuery(sqlReports); while(rs.next()){ SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); out.setText(sdf.format(rs.getString("timeout"))); String r= sdf.format(cal.getTime()); if (cal.getTime() - out.getText() > 10) { } – ar1020 Jan 24 '19 at 15:13
  • What error are you getting? – LinFelix Jan 24 '19 at 15:15
  • 1
    Post code in the question and not as a comment. – Joakim Danielson Jan 24 '19 at 15:15
  • the error is bad operand types for binary operator '-' – ar1020 Jan 24 '19 at 15:20
  • You can't format a string with `SimpleDateFormat.format()`, what type is `timeout` in the database? Also, we don't know the type of `cal`and `out`. Please try to post a complete example. – Joakim Danielson Jan 24 '19 at 15:21
  • varchar=timeout . cal is the current time .out is the textfield which i try to retrieve in the database – ar1020 Jan 24 '19 at 15:25

0 Answers0