コード例 #1
0
ファイル: CustomerDBHelper.java プロジェクト: isavage/InfoGym
  public ArrayList<Customer> getCustomers(String searchType, String searchBy) {
    ArrayList<Customer> customerList = new ArrayList<Customer>();
    String query = "select * from customer where &searchtype like '%&searchBy%'";
    Constants constants = new Constants();
    HashMap<String, String> map = constants.searchTypeToColumn;
    if (searchType.equals("All")) query = "select * from customer";
    else {
      query = query.replace("&searchtype", map.get(searchType));
      query = query.replace("&searchBy", searchBy);
    }
    try {
      ResultSet rs = statement.executeQuery(query);
      while (rs.next()) {
        Customer cust = new Customer();
        cust.setId(rs.getInt(1));
        cust.setFirst_name(rs.getString(2));
        cust.setLast_name(rs.getString(3));
        cust.setAddress(rs.getString(4));
        cust.setTel(rs.getString(5));
        cust.setMobile(rs.getString(6));
        cust.setDob(rs.getTimestamp(7));
        cust.setDoj(rs.getTimestamp(8));

        customerList.add(cust);
      }
    } catch (SQLException ex) {
      Logger.getLogger(CustomerDBHelper.class.getName()).log(Level.SEVERE, null, ex);
    }

    return customerList;
  }
コード例 #2
0
ファイル: CustomerDBHelper.java プロジェクト: isavage/InfoGym
  public static void main(String[] args) {
    Customer cust = new Customer();
    cust.setFirst_name("ankit");

    cust.setLast_name("kaushal");
    cust.setAddress("dwarka");
    cust.setDob(new Timestamp(new Date().getTime()));
    cust.setDoj(new Timestamp(new Date().getTime()));
    cust.setTel("25085435");
    cust.setMobile("9818536576");
    cust.setMembership("yearly");
    CustomerDBHelper dbh = new CustomerDBHelper();
    dbh.saveCustomer(cust);
  }