Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String Make = "";
- String Model = "";
- String Type = "";
- String Genre = "";
- String AttConsole = "";
- String Desc = "";
- if(product.getClass().getName().equals("Models.Game"))
- {
- Game game = (Game)product;
- Genre = String.valueOf(game.getGenre());
- AttConsole = String.valueOf(game.getAttributedConsole());
- Desc = String.valueOf(game.getDescription());
- }
- else if(product.getClass().getName().equals("Models.Console"))
- {
- Console console = (Console)product;
- Make = String.valueOf(console.getMake());
- Model = String.valueOf(console.getModel());
- Desc = String.valueOf(console.getDescription());
- }
- else
- {
- Peripheral peripheral = (Peripheral)product;
- Type = String.valueOf(peripheral.getType());
- Desc = String.valueOf(peripheral.getDescription());
- }
- try
- {
- Class.forName(driver);
- Connection conn = DriverManager.getConnection(connectionString);
- Statement stmt = conn.createStatement();
- stmt.executeUpdate("INSERT INTO Products (ProductName, Price, StockLevel, Description, Genre, AttributedConsole, Make, Model, Type) VALUES "
- + "('" + product.getProductName() + "','" + product.getPrice() + "','" + product.getStocklevel()
- + "','" + Desc + "','" + Genre + "','" + AttConsole +
- "','" + Make + "','" + Model + "'," + Type + ")");
- //sql statement to add new products to database
- conn.close();
- return true;
- }
- catch(Exception ex)
- {
- String message = ex.getMessage();
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement