Exemplo n.º 1
0
Arquivo: SQLDB.java Projeto: Serios/Fe
  public boolean init() {
    database = getNewDatabase();

    database.open();

    if (!database.checkConnection()) {
      return false;
    }

    if (!database.createTable(
        "CREATE TABLE IF NOT EXISTS "
            + accounts
            + "("
            + pname
            + "  varchar(64), "
            + pbalance
            + " double);")) {
      return false;
    }

    if (supportsModification) {
      database.query("ALTER TABLE " + accounts + " MODIFY " + pname + " varchar(64)");
    }

    return true;
  }
Exemplo n.º 2
0
Arquivo: SQLDB.java Projeto: Serios/Fe
  public List<Account> getTopAccounts() {
    String sql =
        "SELECT " + pname + " FROM " + accounts + " ORDER BY " + pbalance + " DESC limit 5";

    List<Account> topAccounts = new ArrayList<Account>();

    ResultSet set = database.query(sql);

    try {
      while (set.next()) {
        topAccounts.add(getAccount(set.getString(pname)));
      }
    } catch (SQLException e) {

    }

    return topAccounts;
  }
Exemplo n.º 3
0
Arquivo: SQLDB.java Projeto: Serios/Fe
  public void clean() {
    String sql = "SELECT * FROM " + accounts + " WHERE " + pbalance + "=?";

    try {
      PreparedStatement prest = database.prepare(sql);

      prest.setDouble(1, plugin.getAPI().getDefaultHoldings());

      ResultSet set = prest.executeQuery();

      boolean executeQuery = false;

      String deleteQuery = "DELETE FROM " + accounts + " WHERE " + pname + " IN (";

      while (set.next()) {
        String name = set.getString(pname);

        if (plugin.getServer().getPlayerExact(name) != null) {
          continue;
        }

        executeQuery = true;

        deleteQuery += "'" + name + "', ";
      }

      prest.close();

      deleteQuery = deleteQuery.substring(0, deleteQuery.length() - 2) + ")";

      if (executeQuery) {
        database.query(deleteQuery);
      }
    } catch (SQLException e) {

    }
  }