コード例 #1
0
  public CustomerEntity getCustomerByUid(String uid) {
    // declare local variables
    CustomerEntity customer = new CustomerEntity();
    ResultSet rs = null;
    PreparedStatement pstmt;
    DBController db = new DBController();
    String dbQuery;

    // Step 1 - connect to database
    db.getConnection();

    // step 2 - declare the SQL statement
    dbQuery = "SELECT * FROM customer where uid = ?";
    pstmt = db.getPreparedStatement(dbQuery);

    try {
      pstmt.setString(1, uid);
      rs = pstmt.executeQuery();
      if (rs.next()) { // first record found
        customer = convertToCustomer(rs);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    // step 4 - close connection
    db.terminate();

    return customer;
  }
コード例 #2
0
  public CustomerEntity getTellerById(String id) {
    // declare local variables
    CustomerEntity teller = null;
    ResultSet rs = null;
    DBController db = new DBController();
    String dbQuery;
    PreparedStatement pstmt;

    // step 1 - connect to database
    db.getConnection();

    // step 2 - declare the SQL statement
    dbQuery = "SELECT * FROM customer WHERE id = ? and enabled = 1";
    pstmt = db.getPreparedStatement(dbQuery);

    // step 3 - execute query
    try {
      pstmt.setString(1, id);
      rs = pstmt.executeQuery();
      if (rs.next()) { // first record found
        teller = convertToCustomer(rs);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    // step 4 - close connection
    db.terminate();

    return teller;
  }
コード例 #3
0
  public boolean deleteTeller(String uid) {
    // declare local variables
    boolean success = false;
    DBController db = new DBController();
    String dbQuery;
    PreparedStatement pstmt;

    db.getConnection();

    dbQuery = "UPDATE customer SET banker = '0' WHERE uid = ? and enabled = 1";
    pstmt = db.getPreparedStatement(dbQuery);

    try {
      pstmt.setString(1, uid);
      if (pstmt.executeUpdate() == 1) success = true;
      pstmt.close();
    } catch (Exception e) {
      e.printStackTrace();
    }

    // step 4 - close connection
    db.terminate();

    return success;
  }
コード例 #4
0
  // -------------------------TELLER--------------------------------
  public boolean createTellerWithUid(String uid) {
    boolean success = false;
    DBController db = new DBController();
    String dbQuery;
    PreparedStatement pstmt;

    // get connection
    db.getConnection();

    // update customer 'banker' attribute with specified uid
    // helps with login
    dbQuery = "UPDATE customer SET banker = '1' WHERE uid = ? and enabled = 1";
    pstmt = db.getPreparedStatement(dbQuery);

    try {
      pstmt.setString(1, uid);
      if (pstmt.executeUpdate() == 1) {
        success = true;
      }
      System.out.println(pstmt.executeUpdate());
      pstmt.close();
    } catch (Exception e) {
      e.printStackTrace();
    }

    // step 4 - close connection
    db.terminate();

    return success;
  }
コード例 #5
0
  public boolean deleteCustomerByUid(String uid) {
    // declare local variables
    boolean success = false;
    DBController db = new DBController();
    String dbQuery;
    PreparedStatement pstmt;

    // step 1 - establish connection to database
    db.getConnection();

    // step 2 - declare the SQL statement
    dbQuery = "DELETE FROM customer WHERE uid = ?";
    pstmt = db.getPreparedStatement(dbQuery);

    // step 3 - to delete record using executeUpdate method
    try {
      pstmt.setString(1, uid);
      if (pstmt.executeUpdate() == 1) success = true;
      pstmt.close();
    } catch (Exception e) {
      e.printStackTrace();
    }

    // step 4 - close connection
    db.terminate();

    return success;
  }
コード例 #6
0
  public boolean updateCustomerClassByUid(String classs, String uid) {
    boolean success = false;
    DBController db = new DBController();
    String dbQuery;
    PreparedStatement pstmt;

    // step 1 - establish connection to database
    db.getConnection();

    // step 2 - declare the SQL statement
    dbQuery = "UPDATE customer SET classs = ? WHERE uid = ?";
    pstmt = db.getPreparedStatement(dbQuery);

    try {
      pstmt.setString(1, classs);
      pstmt.setString(2, uid);

      // step 3 - to update record using executeUpdate method
      if (pstmt.executeUpdate() == 1) success = true;
      pstmt.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
    System.out.println(success);

    // step 4 - close connection
    db.terminate();

    return success;
  }
コード例 #7
0
  public List<CustomerEntity> retrieveAllCustomerByName(String name) {
    // declare local variables
    ArrayList<CustomerEntity> list = new ArrayList<CustomerEntity>();
    ResultSet rs = null;
    PreparedStatement pstmt = null;
    DBController db = new DBController();
    String dbQuery;

    // Step 1 - connect to database
    db.getConnection();

    // step 2 - declare the SQL statement
    dbQuery = "SELECT * FROM customer where name LIKE ? and enabled = 1";
    pstmt = db.getPreparedStatement(dbQuery);

    try {
      pstmt.setString(1, "%" + name + "%");

      System.out.println(name);

      rs = pstmt.executeQuery();

      while (rs.next()) {
        CustomerEntity customer = convertToCustomer(rs);
        list.add(customer);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    // step 4 - close connection
    db.terminate();

    return list;
  }
コード例 #8
0
  public boolean toggleAccount(String nric) {
    DBController db = new DBController();
    boolean success = false;
    String dbQuery;
    PreparedStatement pstmt;
    db.getConnection();

    // step 2 - declare the SQL statement
    dbQuery = "UPDATE customer SET enabled = !enabled WHERE nric = ?";
    pstmt = db.getPreparedStatement(dbQuery);
    // step 3 - to delete record using executeUpdate method
    try {
      pstmt.setString(1, nric);
      if (pstmt.executeUpdate() == 1) success = true;
      pstmt.close();
    } catch (Exception e) {
      e.printStackTrace();
    }

    // step 4 - close connection
    db.terminate();
    return success;
  }