コード例 #1
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;
  }
コード例 #2
0
  public List<CustomerEntity> getTopFiveCustomerWithdraw() {
    // declare local variables
    ArrayList<CustomerEntity> list = new ArrayList<CustomerEntity>();
    ResultSet rs = null;
    DBController db = new DBController();
    String dbQuery;

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

    // step 2 - declare the SQL statement
    dbQuery = "select * from customer group by withdraw DESC limit 5;";

    // step 3 - using DBController readRequest method
    rs = db.readRequest(dbQuery);
    try {
      while (rs.next()) {
        CustomerEntity customer = convertToCustomer(rs);
        list.add(customer);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

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

    return list;
  }
コード例 #3
0
  public List<CustomerEntity> retrieveAllCustomer() {
    // declare local variables
    ArrayList<CustomerEntity> list = new ArrayList<CustomerEntity>();
    ResultSet rs = 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 enabled = 1";

    // step 3 - using DBController readRequest method
    rs = db.readRequest(dbQuery);
    try {
      while (rs.next()) {
        CustomerEntity customer = convertToCustomer(rs);
        list.add(customer);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

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

    return list;
  }
コード例 #4
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;
  }
コード例 #5
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;
  }
コード例 #6
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;
  }
コード例 #7
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;
  }
コード例 #8
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;
  }
コード例 #9
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;
  }
コード例 #10
0
  private void showResults(String query) {
    setNewButtonManager();
    Cursor cursor = DBController.searchPhone(query, mButtonManager);

    if (cursor == null) {
      // nothing
    } else {
      String[] from = new String[] {"Name"};
      int[] to = new int[] {R.id.projectionResult};

      SimpleCursorAdapter phones =
          new SimpleCursorAdapter(this, R.xml.phoneprojection, cursor, from, to, 1);
      if (query.equals("")) {
        listView.setAdapter(null);
      } else {
        listView.setAdapter(phones);
        listView.setOnItemClickListener(
            new OnItemClickListener() {
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Cursor cursor = (Cursor) listView.getItemAtPosition(position);

                String name = cursor.getString(cursor.getColumnIndexOrThrow("Name"));

                Intent intent = new Intent();
                intent.putExtra("Phone", name);
                intent.putExtra("buttonManager", mButtonManager);
                setResult(Activity.RESULT_OK, intent);
                cursor.close();
                finish();
              }
            });
      }
    }
  }
コード例 #11
0
 // load and test driver
 // if it's not there, put out an exception
 public CustomerDAO() {
   try {
     db.testDriver();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
コード例 #12
0
ファイル: CreditCardDAO.java プロジェクト: Sameow/simplyTECH
  public static boolean updateCreditCard(CreditCard cc, int ID) throws SQLException {
    String cardNumber = cc.getCardNumber();
    int expiryMonth = cc.getExpiryMonth();
    int expiryYear = cc.getExpiryYear();
    String expiryDate = cc.getExpiryDate();
    String cardHolderName = cc.getCardHolderName();
    String country = cc.getCountry();
    int CVC = cc.getCVC();
    String streetAddress = cc.getStreetAddress();
    String cardType = cc.getCardType();
    boolean success = false;
    DBController db = new DBController();
    String dbQuery =
        "UPDATE creditcard set CardNumber = '"
            + cardNumber
            + "',"
            + "ExpiryMonth='"
            + expiryMonth
            + "',ExpiryYear='"
            + expiryYear
            + "',"
            + "ExpiryDate='"
            + expiryDate
            + "',CardHolderName='"
            + cardHolderName
            + "',"
            + "Country='"
            + country
            + "',CVC='"
            + CVC
            + "',StreetAddress='"
            + streetAddress
            + "',"
            + "cardType='"
            + cardType
            + "'WHERE ID = '"
            + ID
            + "'";
    db.getConnection();

    if (db.updateRequest(dbQuery) == 1) {
      success = true;
    }
    db.terminate();
    return success;
  }
コード例 #13
0
  public void editKampus(View view) {
    HashMap<String, String> queryValues = new HashMap<String, String>();
    txtKampusName = (EditText) findViewById(R.id.txtKampusName);
    txtEditAlamat = (EditText) findViewById(R.id.txtEditAlamat);
    Intent objIntent = getIntent();
    String kampusId = objIntent.getStringExtra("kampusId");
    queryValues.put("kampusId", kampusId);
    queryValues.put("kampusName", txtKampusName.getText().toString());
    queryValues.put("alamat", txtEditAlamat.getText().toString());

    controller.updateKampus(queryValues);
    this.callHomeActivity(view);
  }
コード例 #14
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;
  }
コード例 #15
0
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_edit_kampus);
   txtKampusName = (EditText) findViewById(R.id.txtKampusName);
   txtEditAlamat = (EditText) findViewById(R.id.txtEditAlamat);
   Intent objIntent = getIntent();
   String kampusId = objIntent.getStringExtra("kampusId");
   Log.d("Reading: ", "Reading all kampus..");
   HashMap<String, String> kampusList = controller.getKampusInfo(kampusId);
   Log.d("kampusName", kampusList.get("kampusName"));
   if (kampusList.size() != 0) {
     txtKampusName.setText(kampusList.get("kampusName"));
     txtEditAlamat.setText(kampusList.get("alamat"));
   }
 }
コード例 #16
0
ファイル: ScoreDB.java プロジェクト: Benpai/OpsuRefined
  /** Initializes the database connection. */
  public static void init() {
    // create a database connection
    connection = DBController.createConnection(Options.SCORE_DB.getPath());
    if (connection == null) return;

    // run any database updates
    updateDatabase();

    // create the database
    createDatabase();

    // prepare sql statements
    try {
      insertStmt =
          connection.prepareStatement(
              // TODO: There will be problems if multiple replays have the same
              // timestamp (e.g. when imported) due to timestamp being the primary key.
              "INSERT OR IGNORE INTO scores VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
      selectMapStmt =
          connection.prepareStatement(
              "SELECT * FROM scores WHERE "
                  + "MID = ? AND title = ? AND artist = ? AND creator = ? AND version = ?");
      selectMapSetStmt =
          connection.prepareStatement(
              "SELECT * FROM scores WHERE "
                  + "MSID = ? AND title = ? AND artist = ? AND creator = ? ORDER BY version DESC");
      deleteSongStmt =
          connection.prepareStatement(
              "DELETE FROM scores WHERE "
                  + "MID = ? AND title = ? AND artist = ? AND creator = ? AND version = ?");
      deleteScoreStmt =
          connection.prepareStatement(
              "DELETE FROM scores WHERE "
                  + "timestamp = ? AND MID = ? AND MSID = ? AND title = ? AND artist = ? AND "
                  + "creator = ? AND version = ? AND hit300 = ? AND hit100 = ? AND hit50 = ? AND "
                  + "geki = ? AND katu = ? AND miss = ? AND score = ? AND combo = ? AND perfect = ? AND mods = ? AND "
                  + "replay = ? AND playerName = ?");
    } catch (SQLException e) {
      ErrorHandler.error("Failed to prepare score statements.", e, true);
    }
  }
コード例 #17
0
 public void removeKampus(View view) {
   Intent objIntent = getIntent();
   String kampusId = objIntent.getStringExtra("kampusId");
   controller.deleteKampus(kampusId);
   this.callHomeActivity(view);
 }
コード例 #18
0
ファイル: CreditCardDAO.java プロジェクト: Sameow/simplyTECH
  public static boolean createCreditCard(CreditCard cc) throws SQLException {
    int id = 0;
    Statement stmt = null;
    Connection con = null;
    con =
        DriverManager.getConnection(
            "jdbc:mysql://localhost:8888/simplytech", "simplyTECH", "hahaudie");
    stmt = con.createStatement();
    String query = "SELECT MAX(ID) FROM person";
    ResultSet rs = stmt.executeQuery(query);
    while (rs.next()) {
      id = rs.getInt("MAX(ID)");
    }
    String cardNumber = cc.getCardNumber();
    int expiryMonth = cc.getExpiryMonth();
    int expiryYear = cc.getExpiryYear();
    String expiryDate = cc.getExpiryDate();
    String cardHolderName = cc.getCardHolderName();
    String country = cc.getCountry();
    int CVC = cc.getCVC();
    String streetAddress = cc.getStreetAddress();
    String cardType = cc.getCardType();

    boolean success = false;
    DBController db = new DBController();

    String dbQuery =
        "INSERT INTO creditcard (ID,CardNumber,ExpiryMonth,ExpiryYear,ExpiryDate,CardHolderName,Country,"
            + "CVC,StreetAddress,CardType) VALUES ('"
            + id
            + "','"
            + cardNumber
            + "','"
            + expiryMonth
            + "','"
            + expiryYear
            + "','"
            + expiryDate
            + "','"
            + cardHolderName
            + "','"
            + country
            + "','"
            + CVC
            + "','"
            + streetAddress
            + "','"
            + cardType
            + "')";
    if (db.updateRequest(dbQuery) == 1) {
      success = true;
    }
    if (rs != null) {
      try {
        rs.close();
      } catch (Exception e) {
      }
      rs = null;
    }

    if (stmt != null) {
      try {
        stmt.close();
      } catch (Exception e) {
      }
      stmt = null;
    }

    if (currentCon != null) {
      try {
        currentCon.close();
      } catch (Exception e) {
      }

      currentCon = null;
    }
    return success;
  }
コード例 #19
0
 private static Dao<Colleage, String> getDao() throws SQLException, DBNotInitializeException {
   return DBController.getDB().getDao(Colleage.class);
 }