Handling variables from another class when saving from ArrayList to MySQL database
<p>I am creating a Rpg game. Now, the game progress is saved to a txt file. I have created a database which will handle the save game instead. Currently I trying to connect the save game ArrayList to a MySQL table. All variables in the ArrayList are created in the Player class and inserted into the ArrayList. This is a snippet of the original code:</p>

<pre><code>public void save(Player p) {
    clearData();

    ArrayList&lt;Object&gt; saveGame = new ArrayList&lt;&gt;();
    saveGame.add(p.getName());
</code></pre>

<p>Since I have rewritten the code to make it possible to store the data in the database, I am getting syntax errors (can't find symbol) when I am trying to insert "Player p" into the new code. I have try the insert it in the arguments, but I am getting syntax errors. How do I do this, now when the code look like this:</p>

<pre><code>public void save(ArrayList&lt;ArrayList&lt;Object&gt;&gt; saveGame) {

    conn = Sqlprogress.ConnectDB();

    String query = " insert into GameProgress (Name, CurrLoc, Strength, Constitution, Dexterity, Hitpoints, Level, xP, xpToLvlUp, ArmorClass, setNrOfPotions, EqWeapon)"
            + " vaules (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    PreparedStatement ps = conn.prepareStatement(insert);
    clearData();

    for (ArrayList&lt;Object&gt; ar1 : saveGame) {
        ps.setString(1, p.getName());                  //Spelarens namn
        ps.setString(2, p.getCurrLoc());               //Spelarens position
        ps.setString(3, p.getStrength());              //Styrka
        ps.setString(4, p.getConstitution());          //Uthållighet
        ps.setString(5, p.getDexterity());             //Smidighet
        ps.setString(6, p.getHitpoints());             //Liv 
        ps.setString(7, p.getLevel());                 //Level
        ps.setString(8, p.xp());                 //Level
        ps.setString(9, p.getxPToLvlUp());             //Erfarenhetsgränsen för att gå upp i level
        ps.setString(10, p.getArmorClass());            //Armorclass
        ps.setString(11, p.getNrOfPotions());           //Antal hälsodrycker
        ps.setString(12, p.getEqWeapon().getName());    //Utrustat vapen (namnet på vapnet sparas)

        //Lägger till allt i inventariet i listan, det är namnen på föremålen sparas
        //Lägger till allt i inventariet i listan, det är namnen på föremålen sparas
        for (Object element : p.getInventory()) {
            if (element instanceof Weapon) {
                saveGame.add(((Weapon) element).getName());
            } else if (element instanceof Item) {
                saveGame.add(((Item) element).getName());
            } else if (element instanceof Armor) {
                saveGame.add(((Armor) element).getName());
            }
        }
    }
</code></pre>