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 {
statement.close();
return null;
}
}
} catch (SQLException e) {
Logger.getLogger().exception(null, "Failed to get API Account.", e, this.getClass());
}
return null;
}