Esempio n. 1
1
 @Override
 public User mapRow(ResultSet rs, int rowNum) throws SQLException {
   // id, username, email, password, salt, identity_verified, nickname,
   // gender, job, phone, telephone, avatar, signature, speciality,
   // preference, province, city, district, address, created_on,
   // version, enable
   User user = new User();
   user.setId(rs.getInt("id"));
   user.setUsername(rs.getString("username"));
   user.setEmail(rs.getString("email"));
   user.setPassword(rs.getString("password"));
   user.setSalt(rs.getString("salt"));
   user.setIdentityVerified(rs.getBoolean("identity_verified"));
   user.setNickname(rs.getString("nickname"));
   user.setGender(rs.getString("gender"));
   user.setJob(rs.getString("job"));
   user.setPhone(rs.getString("phone"));
   user.setTelephone(rs.getString("telephone"));
   user.setAvatar(rs.getString("avatar"));
   user.setSignature(rs.getString("signature"));
   user.setSpeciality(rs.getString("speciality"));
   user.setPreference(rs.getString("preference"));
   user.setProvince(rs.getString("province"));
   user.setCity(rs.getString("city"));
   user.setDistrict(rs.getString("district"));
   user.setAddress(rs.getString("address"));
   user.setCreatedOn(rs.getTimestamp("created_on"));
   user.setEnable(rs.getBoolean("enable"));
   return user;
 }
Esempio n. 2
0
  /** 保存用户帐号 */
  @Override
  public void save(User user) {
    user.setCreatedOn(new Date());
    try {
      Connection connection = super.getConnection();
      PreparedStatement statement =
          connection.prepareStatement(SAVE_SQL, Statement.RETURN_GENERATED_KEYS);
      statement.setString(1, user.getUsername());
      statement.setString(2, user.getEmail());
      statement.setString(3, user.getPassword());
      statement.setString(4, user.getSalt());
      statement.setString(5, user.getNickname());
      statement.setString(6, user.getGender());
      statement.setString(7, user.getJob());
      statement.setString(8, user.getPhone());
      statement.setString(9, user.getTelephone());
      statement.setString(10, user.getAvatar());
      statement.setString(11, user.getSignature());
      statement.setString(12, user.getSpeciality());
      statement.setString(13, user.getPreference());
      statement.setString(14, user.getProvince());
      statement.setString(15, user.getCity());
      statement.setString(16, user.getDistrict());
      statement.setString(17, user.getAddress());
      statement.setTimestamp(18, new Timestamp(user.getCreatedOn().getTime()));

      statement.execute();
      ResultSet rs = statement.getGeneratedKeys();
      while (rs.next()) {
        user.setId(rs.getInt(1));
      }
      rs.close();
      statement.close();
      logger.debug("saved {}", user);
    } catch (SQLException e) {
      throw new BusinessException("Database exception", e);
    }
  }