Example #1
0
 /**
  * 查询 用户名 密码
  *
  * @param user
  */
 public User selectUsPs(User user) {
   QueryRunner queryRunner = new QueryRunner(JdbcUtils.getDataSource());
   String sql = "SELECT * FROM user WHERE username = ? AND password = ?";
   try {
     User query =
         queryRunner.query(
             sql,
             new BeanHandler<User>(User.class),
             new Object[] {user.getUsername(), user.getPassword()});
     return query;
   } catch (SQLException e) {
     e.printStackTrace();
     return null;
   }
 }
  @Override
  public boolean isValidUsernameAndPassword(String username, String password) {
    list = getAll();
    if (username != null || password != null) {
      LOG.log(Level.INFO, " Login: "******" Password:"******" List size: " + list.size());
      for (int i = 0; i < list.size(); i++) {

        User user = list.get(i);
        LOG.log(Level.INFO, " Users: " + user.toString());
        if (user.getUsername().equals(username) && user.getPassword().equals(password)) {
          return true;
        }
      }
    }
    return false;
  }
Example #3
0
 /** 插入数据 */
 public Integer insertUser(User user) {
   QueryRunner queryRunner = new QueryRunner(JdbcUtils.getDataSource());
   try {
     String sql = "INSERT INTO user VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
     Object param[] = {
       getID(),
       user.getUsername(),
       user.getPassword(),
       user.getSex(),
       user.getProfession(),
       user.getFavourite(),
       user.getNote(),
       user.getType()
     };
     int update = queryRunner.update(sql, param);
     return update;
   } catch (SQLException e) {
     e.printStackTrace();
     return null;
   }
 }
Example #4
0
  /**
   * 数据库操作 更新个人用户数据
   *
   * @param user
   */
  public void updateinfo(User user) {
    QueryRunner queryRunner = new QueryRunner(JdbcUtils.getDataSource());

    String sql =
        "UPDATE user SET username = ?, password = ?, sex = ?, profession = ?, favourite = ?, note = ?  WHERE id = ?;";

    try {
      queryRunner.update(
          sql,
          new Object[] {
            user.getUsername(),
            user.getPassword(),
            user.getSex(),
            user.getProfession(),
            user.getFavourite(),
            user.getNote(),
            user.getId()
          });
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }