Exemplo n.º 1
0
  private BuddyTable() {

    Connection con = null;
    PreparedStatement charIdPS = null;
    ResultSet charIdRS = null;
    try {
      con = L1DatabaseFactory.getInstance().getConnection();
      charIdPS = con.prepareStatement("SELECT distinct(char_id) as char_id FROM character_buddys");

      charIdRS = charIdPS.executeQuery();
      PreparedStatement buddysPS = null;
      ResultSet buddysRS = null;
      while (charIdRS.next()) {
        try {
          buddysPS =
              con.prepareStatement(
                  "SELECT buddy_id, buddy_name FROM character_buddys WHERE char_id = ?");
          int charId = charIdRS.getInt("char_id");
          buddysPS.setInt(1, charId);
          L1Buddy buddy = new L1Buddy(charId);

          buddysRS = buddysPS.executeQuery();
          while (buddysRS.next()) {
            buddy.add(buddysRS.getInt("buddy_id"), buddysRS.getString("buddy_name"));
          }

          _buddys.put(buddy.getCharId(), buddy);
        } catch (Exception e) {
          _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
        } finally {
          SQLUtil.close(buddysRS);
          SQLUtil.close(buddysPS);
        }
      }
      _log.config("loaded " + _buddys.size() + " character's buddylists");
    } catch (SQLException e) {
      _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    } finally {
      SQLUtil.close(charIdRS);
      SQLUtil.close(charIdPS);
      SQLUtil.close(con);
    }
  }
Exemplo n.º 2
0
  public void removeBuddy(int charId, String buddyName) {
    Connection con = null;
    PreparedStatement pstm = null;
    L1Buddy buddy = getBuddyTable(charId);
    if (!buddy.containsName(buddyName)) {
      return;
    }

    try {
      con = L1DatabaseFactory.getInstance().getConnection();
      pstm = con.prepareStatement("DELETE FROM character_buddys WHERE char_id=? AND buddy_name=?");
      pstm.setInt(1, charId);
      pstm.setString(2, buddyName);
      pstm.execute();

      buddy.remove(buddyName);
    } catch (SQLException e) {
      _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    } finally {
      SQLUtil.close(pstm);
      SQLUtil.close(con);
    }
  }