ResultSet rs = stm.executeQuery("SELECT count(*) FROM `hs` WHERE `username` ='"+c.playerName+"' LIMIT 1");
int rows = 0;
try
{
rs.last();
rows = rs.getRow();
rs.beforeFirst();
}
catch(Exception ex)
{
ex.printStackTrace();
return false;
}
if(rows > 0)
{
query("UPDATE `hs` SET `overall_lvl` = '"+overallLVL+"',`overall_xp` = '"+overallXP+"',`attack_lvl` = '"+c.playerLevel[0]+"',`attack_xp` = '"+c.playerXP[0]+"',`defence_lvl` = '"+c.playerLevel[1]+"',`defence_xp` = '"+c.playerXP[1]+"',`strength_lvl` = '"+c.playerLevel[2]+"',`strength_xp` = '"+c.playerXP[2]+"',`ranged_lvl` = '"+c.playerLevel[3]+"',`ranged_xp` = '"+c.playerXP[3]+"',`prayer_lvl` = '"+c.playerLevel[4]+"',`prayer_xp` = '"+c.playerXP[4]+"',`magic_lvl` = '"+c.playerLevel[5]+"',`magic_xp` = '"+c.playerXP[5]+"',`cooking_lvl` = '"+c.playerLevel[6]+"',`cooking_xp` = '"+c.playerXP[6]+"',`woodcutting_lvl` = '"+c.playerLevel[7]+"',`woodcutting_xp` = '"+c.playerXP[7]+"',`fletching_lvl` = '"+c.playerLevel[8]+"',`fletching_xp` = '"+c.playerXP[8]+"',`fishing_lvl` = '"+c.playerLevel[9]+"',`fishing_xp` = '"+c.playerXP[9]+"',`firemaking_lvl` = '"+c.playerLevel[10]+"',`firemaking_xp` = '"+c.playerXP[10]+"',`crafting_lvl` = '"+c.playerLevel[11]+"',`crafting_xp` = '"+c.playerXP[11]+"',`smithing_lvl` = '"+c.playerLevel[12]+"',`smithing_xp` = '"+c.playerXP[12]+"',`mining_lvl` = '"+c.playerLevel[13]+"',`mining_xp` = '"+c.playerXP[13]+"',`herblore_lvl` = '"+c.playerLevel[14]+"',`herblore_xp` = '"+c.playerXP[14]+"',`agility_lvl` = '"+c.playerLevel[15]+"',`agility_xp` = '"+c.playerXP[15]+"',`thieving_lvl` = '"+c.playerLevel[16]+"',`thieving_xp` = '"+c.playerXP[16]+"',`slayer_lvl` = '"+c.playerLevel[17]+"',`slayer_xp` = '"+c.playerXP[17]+"',`farming_lvl` = '"+c.playerLevel[18]+"',`farming_xp` = '"+c.playerXP[18]+"',`runecrafting_lvl` = '"+c.playerLevel[19]+"',`runecrafting_xp` = '"+c.playerXP[19]+"',WHERE `username` = '"+c.playerName+"'");
}
else
{
query("INSERT INTO `hs` SET `username` = '"+c.playerName+"', `overall_lvl` = '"+overallLVL+"',`overall_xp` = '"+overallXP+"',`attack_lvl` = '"+c.playerLevel[0]+"',`attack_xp` = '"+c.playerXP[0]+"',`defence_lvl` = '"+c.playerLevel[1]+"',`defence_xp` = '"+c.playerXP[1]+"',`strength_lvl` = '"+c.playerLevel[2]+"',`strength_xp` = '"+c.playerXP[2]+"',`ranged_lvl` = '"+c.playerLevel[3]+"',`ranged_xp` = '"+c.playerXP[3]+"',`prayer_lvl` = '"+c.playerLevel[4]+"',`prayer_xp` = '"+c.playerXP[4]+"',`magic_lvl` = '"+c.playerLevel[5]+"',`magic_xp` = '"+c.playerXP[5]+"',`cooking_lvl` = '"+c.playerLevel[6]+"',`cooking_xp` = '"+c.playerXP[6]+"',`woodcutting_lvl` = '"+c.playerLevel[7]+"',`woodcutting_xp` = '"+c.playerXP[7]+"',`fletching_lvl` = '"+c.playerLevel[8]+"',`fletching_xp` = '"+c.playerXP[8]+"',`fishing_lvl` = '"+c.playerLevel[9]+"',`fishing_xp` = '"+c.playerXP[9]+"',`firemaking_lvl` = '"+c.playerLevel[10]+"',`firemaking_xp` = '"+c.playerXP[10]+"',`crafting_lvl` = '"+c.playerLevel[11]+"',`crafting_xp` = '"+c.playerXP[11]+"',`smithing_lvl` = '"+c.playerLevel[12]+"',`smithing_xp` = '"+c.playerXP[12]+"',`mining_lvl` = '"+c.playerLevel[13]+"',`mining_xp` = '"+c.playerXP[13]+"',`herblore_lvl` = '"+c.playerLevel[14]+"',`herblore_xp` = '"+c.playerXP[14]+"',`agility_lvl` = '"+c.playerLevel[15]+"',`agility_xp` = '"+c.playerXP[15]+"',`thieving_lvl` = '"+c.playerLevel[16]+"',`thieving_xp` = '"+c.playerXP[16]+"',`slayer_lvl` = '"+c.playerLevel[17]+"',`slayer_xp` = '"+c.playerXP[17]+"',`farming_lvl` = '"+c.playerLevel[18]+"',`farming_xp` = '"+c.playerXP[18]+"',`runecrafting_lvl` = '"+c.playerLevel[19]+"',`runecrafting_xp` = '"+c.playerXP[19]+"'");
}
當我運行它時,它只會執行插入操作,在第二次運行時它將不會再次執行。我相信這是關於不正確變成int的行。我能做些什麼來正確設置它?在java中設置一個SQL計數作爲變量
請學習如何使用參數,不要使用字符串連接,因爲https://en.wikipedia.org/wiki/SQL_injection – Betlista