//========================================================================
// Program: IDEA_Login.java
//
// Author:  F2-Team2
// This is a sample program written for the UIT2201 Project
//
// This program takes input a name
// output:0 if occupant, 1 if friendly, 2 if name is not found.
//
//
package IDEA_Login;
import java.sql.*;   // LHW: this imports sql related classes
import DBClasses.*;  // LHW: imports database manager and other classes


class Login {

  public static void main(String[] args) {

     // 0=found, 1=not found   (default is 2, not found)
     String found = "2";
	 String pers_handle = args[0];
     // LHW: Create a database connection
     // LHW:  by using the dbManager class provided
     dbManager dbman = new dbManager();
     Connection conn = dbman.getConnection();

     try {
       // To execute query,
       //   first create the sql statement
       //   execute the statement
       //   "catch" the output in "rs" (rs is a set of tuples)
       Statement stmt = conn.createStatement();
       String sql = "SELECT pers_status FROM People WHERE pers_handle = '"+pers_handle+"'";
            // prepare sql stmt
       ResultSet rs = stmt.executeQuery(sql);          // execute query

       while (rs.next()) {                             // process the result

           //found = rs.getString("pers_status");
           found = "0";
           break;
       }
       rs.close();       // close everything (rs, stmt, conn)
       stmt.close();
       conn.close();
    } catch (Exception e) {
      System.out.println("DB Error!"); // error message if exception occurs
      System.out.println(e);
      e.printStackTrace();
    }
    System.out.println(found);
  }
}
