Java SQL Database And Object Storage
<p>I want to create a Java GUI Program.</p>

<p>The Program should allow a user to add items(title,price). When they add an Item, the item must be added to a mySql database aswell as an Item object. This item object then needs to be stored in a collection.</p>

<p>Java ItemObject:</p>

<pre><code>    import java.util.*;
import java.io.Serializable;

class Items implements Serializable{

  private String title;
  private String price;

  public Items(String t, String p) {

     title = t;
     price = p;
  }

  public void setTitle(String t) {
    title = t;
  }
  public String getTitle() {
    return title;
  }

  public void setPrice(String p) {
    price = p;
  }
  public String getPrice() {
    return price;
  }
}
</code></pre>

<p>Shop</p>

<pre><code>import java.util.*;
import java.io.Serializable;
import java.rmi.*;
import java.rmi.server.*;
import java.sql.*;

    class Shop extends UnicastRemoteObject implements ShopInterface, Serializable {


        //Create Array to Store Items and Users
        ArrayList&lt;Items&gt; arrayItems;

        //Database connection data
        Connection conn = null; // connection object

        private final String database = "Shop";
        private final String user = "";
        private final String password = "";
        private final String url = "jdbc:mysql:///" + database;

        protected Shop() throws RemoteException {


            arrayItems = new ArrayList&lt;Items&gt;();


            //Load the driver
            try {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }

            //Establish Connection  
            try {
                conn = DriverManager.getConnection(url,user,password);
            } catch (SQLException e) {
                e.printStackTrace();
            }
            System.out.println("Shop Created and Database Connection Completed");

        }
        //Add Items to Shop
        public void additems(String t, String p)
                throws RemoteException {


            //SQL Insert Statement
            String insertSQL = "INSERT INTO ShopItems(title, price) VALUES('" +
                    t + "','" + p + "')";

            //Try Insert
            try {
            Statement stmt = conn.createStatement();
            int res = stmt.executeUpdate(insertSQL);
                    arrayItems.add(new Items(t, p));

            }
            catch(SQLException se) {
                System.err.println(se);
            }
        }
    }
</code></pre>

<p>Is this the right way to go about it? Would something like this work? ( Not tested this)</p>
