statement.setString(1, acc.getAPIKey()); " VALUES (?, ?, ?, ?, ?)"; PreparedStatement ps = databaseInfo.getConnection().prepareStatement(insertCommand); ps.setString(1, acc.getUserId()); ps.setString(2, acc.getAPIKey()); ps.setBoolean(3, acc.isBlocked()); ps.setLong(4, acc.getTimeIssued()); ps.setInt(5, acc.getUses()); PreparedStatement ps = databaseInfo.getConnection().prepareStatement(update); ps.setString(1, acc.getUserId()); ps.setBoolean(2, acc.isBlocked()); ps.setInt(3, acc.getUses()); ps.setString(4, acc.getAPIKey());
public UserAPIAccount getAPIAccount(String APIKey) { try { if (databaseInfo.getMySQL().checkConnection()) { String dataTableName = String.format("%sapi", databaseInfo.getPrefix()); String query = "SELECT * FROM " + dataTableName + " WHERE API_KEY = ?"; PreparedStatement statement = databaseInfo.getConnection().prepareStatement(query); statement.setString(1, APIKey); ResultSet res = statement.executeQuery(); boolean hasStuff = res.next(); if (hasStuff && res.getString("API_KEY") != null) { UserAPIAccount account = new UserAPIAccount(); account.setAPIKey(APIKey); account.setUserId(res.getString("USER_ID")); account.setBlocked(res.getBoolean("BLOCKED")); account.setTimeIssued(res.getLong("TIME_ISSUED")); account.setUses(res.getInt("USES")); statement.close(); return account; } else { //Data not present. statement.close(); return null; } } } catch (SQLException e) { Logger.getLogger().exception(null, "Failed to get API Account.", e, this.getClass()); } return null; }
UserAPIAccount acc = DatabaseManager.getManager().getAPIAccount(key); if (acc != null) { if (acc.isBlocked()) { Logger.getLogger().api("Attempted to use blocked API Key: " + acc.getAPIKey(), request.getRemoteAddr()); acc.setUses(acc.getUses() + 1); DatabaseManager.getManager().updateAPIAccount(acc);
UserAPIAccount acc = DatabaseManager.getManager().getAPIAccount(key); if (acc != null) { if (acc.isBlocked()) { Logger.getLogger().api("Attempted to use blocked API Key: " + acc.getAPIKey(), request.getRemoteAddr()); acc.setUses(acc.getUses() + 1); DatabaseManager.getManager().updateAPIAccount(acc);
UserAPIAccount acc = DatabaseManager.getManager().getAPIAccount(key); if (acc != null) { if (acc.isBlocked()) { Logger.getLogger().api("Attempted to use blocked API Key: " + acc.getAPIKey(), request.getRemoteAddr()); acc.setUses(acc.getUses() + 1); DatabaseManager.getManager().updateAPIAccount(acc);