Originally Posted by
Michaela
Hello I was wondering if someone could help me decipher this...
I'm not sure what the tables are from the following code, I am trying to rebuild the database structure and I am having some trouble.
I have this:
Code:
package com.RuneZero.core.network.mysql;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.RuneZero.core.util.Utility;
import com.RuneZero.rs2.content.skill.Skills;
import com.RuneZero.rs2.entity.player.Player;
/**
* Performs an upload to the MySQL server containing highscores information.
*/
public final class HiscoreUpdater {
private static ExternalDatabase database = null;
private static ExecutorService executorService = null;
private static boolean prepared = false;
private static long getTotalExperience(Player player) {
return player.getSkill().getTotalExperience();
}
private static int getTotalLevel(Player player) {
return player.getSkill().getTotalLevel();
}
public static void prepare() {
database = new ExternalDatabase("rzadmin", "pass, "localhost/highscores", 3);
database.initialise();
executorService = Executors.newSingleThreadExecutor();
prepared = true;
}
public static void shutdown() {
database.shutdown();
executorService.shutdown();
}
public static void update(Player player) {
if (!prepared) {
throw new IllegalStateException("unprepared");
}
if (database.getPooledConnection() == null) {
return;
}
executorService.submit(() -> {
final int totalLevel = getTotalLevel(player);
final long totalExp = getTotalExperience(player);
int totalPrestige = 0;
for (int prestige : player.getSkillPrestiges()) {
if (prestige > 0) {
totalPrestige += prestige;
}
}
StringBuilder bldr = new StringBuilder(1256);
bldr.append("INSERT INTO highscores (");
bldr.append("`username`");
bldr.append(",`rights`");
bldr.append(",`overall_prestige`");
bldr.append(",`overall_level`");
bldr.append(",`overall_xp`");
for (int skill = 0; skill < Skills.SKILL_COUNT; skill++) {
if (skill == Skills.CONSTRUCTION || skill == Skills.DUNGEONEERING || skill == Skills.SUMMONING) {
continue;
}
String skillName = Skills.SKILL_NAMES[skill];
bldr.append(",`" + skillName + "_xp`");
bldr.append(",`" + skillName + "_prestige`");
}
bldr.append(") VALUES (");
bldr.append("'" + Utility.formatPlayerName(player.getUsername().toLowerCase()) + "'");
bldr.append("," + player.getRights());
bldr.append("," + totalPrestige);
bldr.append("," + totalLevel);
bldr.append("," + totalExp);
for (int skill = 0; skill < Skills.SKILL_COUNT; skill++) {
if (skill == Skills.CONSTRUCTION || skill == Skills.DUNGEONEERING || skill == Skills.SUMMONING) {
continue;
}
bldr.append("," + player.getSkill().getExperience()[skill]);
bldr.append("," + player.getSkillPrestiges()[skill]);
}
bldr.append(")");
bldr.append(" ON DUPLICATE KEY UPDATE ");
bldr.append("`rights`=" + player.getRights());
bldr.append(",`overall_prestige`=" + totalPrestige);
bldr.append(",`overall_level`=" + totalLevel);
bldr.append(",`overall_xp`=" + totalExp);
for (int skill = 0; skill < Skills.SKILL_COUNT; skill++) {
if (skill == Skills.CONSTRUCTION || skill == Skills.DUNGEONEERING || skill == Skills.SUMMONING) {
continue;
}
String skillName = Skills.SKILL_NAMES[skill];
bldr.append(",`" + skillName + "_xp`=" + player.getSkill().getExperience()[skill]);
bldr.append(",`" + skillName + "_prestige`=" + player.getSkillPrestiges()[skill]);
}
database.executeQuery(bldr.toString());
});
}
}
From this code is there anything that is specifying MySQL Tables, if so what are they and how do I know how to identify them? would Skills be a table?
I also have this error code while attempting to connect to the db: any help is much appreciated.
Code:
SQL query failed [failCount: 1]: INSERT INTO highscores (`username`,`rights`,`overall_prestige`,`overall_level`,`overall_xp`,`attack_xp`,`attack_prestige`,`defence_xp`,`defence_prestige`,`strength_xp`,`strength_prestige`,`hitpoints_xp`,`hitpoints_prestige`,`ranged_xp`,`ranged_prestige`,`prayer_xp`,`prayer_prestige`,`magic_xp`,`magic_prestige`,`cooking_xp`,`cooking_prestige`,`woodcutting_xp`,`woodcutting_prestige`,`fletching_xp`,`fletching_prestige`,`fishing_xp`,`fishing_prestige`,`firemaking_xp`,`firemaking_prestige`,`crafting_xp`,`crafting_prestige`,`smithing_xp`,`smithing_prestige`,`mining_xp`,`mining_prestige`,`herblore_xp`,`herblore_prestige`,`agility_xp`,`agility_prestige`,`thieving_xp`,`thieving_prestige`,`slayer_xp`,`slayer_prestige`,`farming_xp`,`farming_prestige`,`runecrafting_xp`,`runecrafting_prestige`,`hunter_xp`,`hunter_prestige`) VALUES ('Test Adsfdsf',0,0,31,1154,0.0,0,0.0,0,0.0,0,1154.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0) ON DUPLICATE KEY UPDATE `rights`=0,`overall_prestige`=0,`overall_level`=31,`overall_xp`=1154,`attack_xp`=0.0,`attack_prestige`=0,`defence_xp`=0.0,`defence_prestige`=0,`strength_xp`=0.0,`strength_prestige`=0,`hitpoints_xp`=1154.0,`hitpoints_prestige`=0,`ranged_xp`=0.0,`ranged_prestige`=0,`prayer_xp`=0.0,`prayer_prestige`=0,`magic_xp`=0.0,`magic_prestige`=0,`cooking_xp`=0.0,`cooking_prestige`=0,`woodcutting_xp`=0.0,`woodcutting_prestige`=0,`fletching_xp`=0.0,`fletching_prestige`=0,`fishing_xp`=0.0,`fishing_prestige`=0,`firemaking_xp`=0.0,`firemaking_prestige`=0,`crafting_xp`=0.0,`crafting_prestige`=0,`smithing_xp`=0.0,`smithing_prestige`=0,`mining_xp`=0.0,`mining_prestige`=0,`herblore_xp`=0.0,`herblore_prestige`=0,`agility_xp`=0.0,`agility_prestige`=0,`thieving_xp`=0.0,`thieving_prestige`=0,`slayer_xp`=0.0,`slayer_prestige`=0,`farming_xp`=0.0,`farming_prestige`=0,`runecrafting_xp`=0.0,`runecrafting_prestige`=0,`hunter_xp`=0.0,`hunter_prestige`=0
you would have a table set up on there with rows that are supposed to match the column values i.e.
Code:
`username`,`rights`,`overall_prestige`,`overall_level`,`overall_xp`,`attack_xp`,`attack_prestige`,`defence_xp`,`defence_prestige`,`strength_xp`,`strength_prestige`,`hitpoints_xp`,`hitpoints_prestige`,`ranged_xp`,`ranged_prestige`,`prayer_xp`,`prayer_prestige`,`magic_xp`,`magic_prestige`,`cooking_xp`,`cooking_prestige`,`woodcutting_xp`,`woodcutting_prestige`,`fletching_xp`,`fletching_prestige`,`fishing_xp`,`fishing_prestige`,`firemaking_xp`,`firemaking_prestige`,`crafting_xp`,`crafting_prestige`,`smithing_xp`,`smithing_prestige`,`mining_xp`,`mining_prestige`,`herblore_xp`,`herblore_prestige`,`agility_xp`,`agility_prestige`,`thieving_xp`,`thieving_prestige`,`slayer_xp`,`slayer_prestige`,`farming_xp`,`farming_prestige`,`runecrafting_xp`,`runecrafting_prestige`,`hunter_xp`,`hunter_prestige`) VALUES ('Test Adsfdsf',0,0,31,1154,0.0,0,0.0,0,0.0,0,1154.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0) ON DUPLICATE KEY UPDATE `rights`=0,`overall_prestige`=0,`overall_level`=31,`overall_xp`=1154,`attack_xp`=0.0,`attack_prestige`=0,`defence_xp`=0.0,`defence_prestige`=0,`strength_xp`=0.0,`strength_prestige`=0,`hitpoints_xp`=1154.0,`hitpoints_prestige`=0,`ranged_xp`=0.0,`ranged_prestige`=0,`prayer_xp`=0.0,`prayer_prestige`=0,`magic_xp`=0.0,`magic_prestige`=0,`cooking_xp`=0.0,`cooking_prestige`=0,`woodcutting_xp`=0.0,`woodcutting_prestige`=0,`fletching_xp`=0.0,`fletching_prestige`=0,`fishing_xp`=0.0,`fishing_prestige`=0,`firemaking_xp`=0.0,`firemaking_prestige`=0,`crafting_xp`=0.0,`crafting_prestige`=0,`smithing_xp`=0.0,`smithing_prestige`=0,`mining_xp`=0.0,`mining_prestige`=0,`herblore_xp`=0.0,`herblore_prestige`=0,`agility_xp`=0.0,`agility_prestige`=0,`thieving_xp`=0.0,`thieving_prestige`=0,`slayer_xp`=0.0,`slayer_prestige`=0,`farming_xp`=0.0,`farming_prestige`=0,`runecrafting_xp`=0.0,`runecrafting_prestige`=0,`hunter_xp`=0.0,`hunter_prestige`=0
the issue here is simple
all you need is to add a SKILL_COUNT which is usually under the code you posted idk why it looks like its incomplete?
Code:
if(rs.getInt("count") > 0) {
stmt.executeUpdate("UPDATE `hs_users` SET overall_xp = '"+overallXp+"', attack_xp = '"+attackXp+"', defence_xp = '"+defenceXp+"', strength_xp = '"+strengthXp+"', constitution_xp = '"+constitutionXp+"', ranged_xp = '"+rangedXp+"', prayer_xp = '"+prayerXp+"', magic_xp = '"+magicXp+"', cooking_xp = '"+cookingXp+"', woodcutting_xp = '"+woodcuttingXp+"', fletching_xp = '"+fletchingXp+"', fishing_xp = '"+fishingXp+"', firemaking_xp = '"+firemakingXp+"', crafting_xp = '"+craftingXp+"', smithing_xp = '"+smithingXp+"', mining_xp = '"+miningXp+"', herblore_xp = '"+herbloreXp+"', agility_xp = '"+agilityXp+"', thieving_xp = '"+thievingXp+"', slayer_xp = '"+slayerXp+"', farming_xp = '"+farmingXp+"', runecrafting_xp = '"+runecraftingXp+"', hunter_xp = '"+hunterXp+"', construction_xp = '"+constructionXp+"', summoning_xp = '"+summoningXp+"', dungeoneering_xp = '"+dungXp+"' WHERE username = '"+username+"'");
} else {
stmt.executeUpdate("INSERT INTO `hs_users` (username, rights, overall_xp, attack_xp, defence_xp, strength_xp, constitution_xp, ranged_xp, prayer_xp, magic_xp, cooking_xp, woodcutting_xp, fletching_xp, fishing_xp, firemaking_xp, crafting_xp, smithing_xp, mining_xp, herblore_xp, agility_xp, thieving_xp, slayer_xp, farming_xp, runecrafting_xp, hunter_xp, construction_xp, summoning_xp, dungeoneering_xp) VALUES ('"+username+"', '"+gameMode+"', '"+overallXp+"', '"+attackXp+"', '"+defenceXp+"', '"+strengthXp+"', '"+constitutionXp+"', '"+rangedXp+"', '"+prayerXp+"', '"+magicXp+"', '"+cookingXp+"', '"+woodcuttingXp+"', '"+fletchingXp+"', '"+fishingXp+"', '"+firemakingXp+"', '"+craftingXp+"', '"+smithingXp+"', '"+miningXp+"', '"+herbloreXp+"', '"+agilityXp+"', '"+thievingXp+"', '"+slayerXp+"', '"+farmingXp+"', '"+runecraftingXp+"', '"+hunterXp+"', '"+constructionXp+"','"+summoningXp+"', '"+dungXp+"')");
}
So add
Code:
if (connection != null) {
try {
stmt = (Statement) connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT COUNT(*) AS count FROM `hs_users` WHERE username='" +username+ "'");
if(rs.next()) {
if(rs.getInt("count") > 0) {
stmt.executeUpdate("UPDATE `hs_users` SET overall_xp = '"+overallXp+"', attack_xp = '"+attackXp+"', defence_xp = '"+defenceXp+"', strength_xp = '"+strengthXp+"', constitution_xp = '"+constitutionXp+"', ranged_xp = '"+rangedXp+"', prayer_xp = '"+prayerXp+"', magic_xp = '"+magicXp+"', cooking_xp = '"+cookingXp+"', woodcutting_xp = '"+woodcuttingXp+"', fletching_xp = '"+fletchingXp+"', fishing_xp = '"+fishingXp+"', firemaking_xp = '"+firemakingXp+"', crafting_xp = '"+craftingXp+"', smithing_xp = '"+smithingXp+"', mining_xp = '"+miningXp+"', herblore_xp = '"+herbloreXp+"', agility_xp = '"+agilityXp+"', thieving_xp = '"+thievingXp+"', slayer_xp = '"+slayerXp+"', farming_xp = '"+farmingXp+"', runecrafting_xp = '"+runecraftingXp+"', hunter_xp = '"+hunterXp+"', construction_xp = '"+constructionXp+"', summoning_xp = '"+summoningXp+"', dungeoneering_xp = '"+dungXp+"' WHERE username = '"+username+"'");
} else {
stmt.executeUpdate("INSERT INTO `hs_users` (username, rights, overall_xp, attack_xp, defence_xp, strength_xp, constitution_xp, ranged_xp, prayer_xp, magic_xp, cooking_xp, woodcutting_xp, fletching_xp, fishing_xp, firemaking_xp, crafting_xp, smithing_xp, mining_xp, herblore_xp, agility_xp, thieving_xp, slayer_xp, farming_xp, runecrafting_xp, hunter_xp, construction_xp, summoning_xp, dungeoneering_xp) VALUES ('"+username+"', '"+gameMode+"', '"+overallXp+"', '"+attackXp+"', '"+defenceXp+"', '"+strengthXp+"', '"+constitutionXp+"', '"+rangedXp+"', '"+prayerXp+"', '"+magicXp+"', '"+cookingXp+"', '"+woodcuttingXp+"', '"+fletchingXp+"', '"+fishingXp+"', '"+firemakingXp+"', '"+craftingXp+"', '"+smithingXp+"', '"+miningXp+"', '"+herbloreXp+"', '"+agilityXp+"', '"+thievingXp+"', '"+slayerXp+"', '"+farmingXp+"', '"+runecraftingXp+"', '"+hunterXp+"', '"+constructionXp+"','"+summoningXp+"', '"+dungXp+"')");
}
}
stmt.close();
connection.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
} else {
System.out.println("Failed to make connection!");
}
return;
}
Depending on what base you're using as this is for Ruse.
tldr;
THE ANSWER TO YOUR PROBLEM IS YOUR MISSING THE COUNT MEANING THE REST OF THE SKILLS WHICH IS USUALLY IN APPEND ORDER LIKE WHAT
YOU GOT GOING RIGHT NOW BUT THIS IS CALLING OUT A SKILL_COUNT THEREFORE THE SKILLCOUNT see this is in your code
Code:
for (int skill = 0; skill < Skills.SKILL_COUNT; skill++) {
so where is SKILL_COUNT?