예제 #1
0
  @Override
  public int updateUser(User user) throws FalhaAcessoAosDadosException {
    PreparedStatement statmnet = null;
    int ret = -1;
    if (user == null) {
      throw new FalhaAcessoAosDadosException("don't update  null user");
    }
    try {
      String sql = " UPDATE  %s SET ";
      sql = format(sql, UserDAO.TABLE_NAME);
      sql += format("  %s=? ,", UserDAO.COLUMN_NAME);
      sql += format("  %s=? ,", UserDAO.COLUMN_password);
      sql += format("  %s=? ", UserDAO.COLUMN_TYPE_USER);

      sql += format("WHERE %s =  ? ", UserDAO.COLUMN_ID);

      statmnet = conn.prepareStatement(sql);
      statmnet.setString(1, user.getName());
      statmnet.setString(2, user.getPasswor());
      statmnet.setString(3, user.getType_user_blog());
      statmnet.setLong(4, user.getId());

      ret = statmnet.executeUpdate();
    } catch (final SQLException e) {
      e.printStackTrace();
      throw new FalhaAcessoAosDadosException(e.getMessage());
    } finally {
      close(statmnet);
    }

    return ret;
  }
예제 #2
0
  private int insertUser(User user, long id) throws FalhaAcessoAosDadosException {
    PreparedStatement statmnet = null;
    int ret = -1;
    if (user == null) {
      return ret;
    }
    try {
      String sql = " INSERT INTO %s ( %s,%s, %s, %s ) VALUES(?, ?, ?, ?) ";
      sql = format(sql, UserDAO.TABLE_NAME);
      sql = format(sql, UserDAO.COLUMN_ID);
      sql = format(sql, UserDAO.COLUMN_NAME);
      sql = format(sql, UserDAO.COLUMN_password);
      sql = format(sql, UserDAO.COLUMN_TYPE_USER);

      statmnet = conn.prepareStatement(sql);
      statmnet.setLong(1, id);
      statmnet.setString(2, user.getName());
      statmnet.setString(3, user.getPasswor());
      statmnet.setString(4, user.getType_user_blog());

      ret = statmnet.executeUpdate();
    } catch (final SQLException e) {
      e.printStackTrace();
      throw new FalhaAcessoAosDadosException(e.getMessage());
    } finally {
      close(statmnet);
    }

    return ret;
  }
예제 #3
0
  private List<User> parceResult(ResultSet result) throws SQLException {

    final List<User> users = new ArrayList<User>();
    while (result.next()) {

      final User cust = new User();
      cust.setId(result.getLong(UserDAO.COLUMN_ID));
      cust.setName(result.getString(UserDAO.COLUMN_NAME));
      cust.setPasswor(result.getString(UserDAO.COLUMN_password));
      // cust.setPermissions(permissions);//FIXME
      cust.setType_user_blog(result.getString(UserDAO.COLUMN_TYPE_USER));
      users.add(cust);
    }
    return users;
  }