Esempio n. 1
0
 public static boolean checkByEmail(String email) {
   boolean valid = true;
   try {
     conn = RDSManagement.getConnection();
     st = (Statement) conn.createStatement();
     String sql = "select * from User where email = '" + email + "';";
     System.out.println(sql);
     ResultSet rs = st.executeQuery(sql);
     if (rs.next()) {
       valid = false;
     }
   } catch (SQLException e) {
     System.out.println(e.getMessage());
   } catch (Exception e) {
     System.out.println(e.getMessage());
   } finally {
     try {
       st.close();
       conn.close();
     } catch (SQLException e) {
       e.printStackTrace();
     }
   }
   return valid;
 }
Esempio n. 2
0
 public static boolean checkByUsername(String userName) {
   boolean valid = true;
   try {
     conn = RDSManagement.getConnection();
     st = (Statement) conn.createStatement();
     String sql = "select * from User where userName = '******';";
     System.out.println(sql);
     ResultSet rs = st.executeQuery(sql);
     if (rs.next()) {
       valid = false;
     }
     // return user;
   } catch (SQLException e) {
     System.out.println(e.getMessage());
   } catch (Exception e) {
     System.out.println(e.getMessage());
   } finally {
     try {
       st.close();
       conn.close();
     } catch (SQLException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
   return valid;
 }
Esempio n. 3
0
  public static User getUserByUsername(String userName) {
    User user = null;

    try {
      conn = RDSManagement.getConnection();
      st = (Statement) conn.createStatement();
      String sql = "select * from User where userName = '******';";
      System.out.println(sql);
      ResultSet rs = st.executeQuery(sql);
      if (rs.next()) {
        user = constructUserFromResultSet(rs);
      }
      // return user;
    } catch (SQLException e) {
      System.out.println(e.getMessage());
    } catch (Exception e) {
      System.out.println(e.getMessage());
    } finally {
      try {
        st.close();
        conn.close();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return user;
  }
Esempio n. 4
0
 public static int getMaxUserID() {
   User user = null;
   int maxId = 0;
   try {
     conn = RDSManagement.getConnection();
     st = (Statement) conn.createStatement();
     String sql = "SELECT MAX(uid) maxid FROM User;";
     System.out.println(sql);
     ResultSet rs = st.executeQuery(sql);
     if (rs.next()) {
       maxId = rs.getInt("maxid");
     }
     // return user;
   } catch (SQLException e) {
     System.out.println(e.getMessage());
   } catch (Exception e) {
     System.out.println(e.getMessage());
   } finally {
     try {
       st.close();
       conn.close();
     } catch (SQLException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
   return maxId;
 }
Esempio n. 5
0
  public static int updateOneUser(User user) {
    int uid = user.getUid();
    String userName = user.getUserName();
    String email = user.getEmail();
    String password = user.getPassword();
    try {
      conn = RDSManagement.getConnection();
      st = (Statement) conn.createStatement();
      String sql =
          "update User set email ='"
              + email
              + "', password ='******' where uid = "
              + uid
              + ";";
      System.out.println(sql);
      st.executeUpdate(sql);
      System.out.println("Update user: " + uid);

    } catch (SQLException e) {
      System.out.println(e.getMessage());
    } catch (Exception e) {
      System.out.println(e.getMessage());
    } finally {
      try {
        st.close();
        conn.close();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return uid;
  }
Esempio n. 6
0
  public static int insertOneUser(User user) {
    int uid = getMaxUserID() + 1;
    String userName = user.getUserName();
    String email = user.getEmail();
    String password = user.getPassword();
    try {
      conn = RDSManagement.getConnection();
      st = (Statement) conn.createStatement();
      String sql =
          "insert into User values("
              + uid
              + ",'"
              + userName
              + "', '"
              + email
              + "','"
              + password
              + "');";
      System.out.println(sql);
      int count = st.executeUpdate(sql);
      System.out.println("Inserted " + count + " items into Event");

    } catch (SQLException e) {
      System.out.println(e.getMessage());
    } catch (Exception e) {
      System.out.println(e.getMessage());
    } finally {
      try {
        st.close();
        conn.close();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return uid;
  }