Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. String Make = "";
  2. String Model = "";
  3. String Type = "";
  4. String Genre = "";
  5. String AttConsole = "";
  6. String Desc = "";
  7.  
  8. if(product.getClass().getName().equals("Models.Game"))
  9. {
  10. Game game = (Game)product;
  11. Genre = String.valueOf(game.getGenre());
  12. AttConsole = String.valueOf(game.getAttributedConsole());
  13. Desc = String.valueOf(game.getDescription());
  14. }
  15. else if(product.getClass().getName().equals("Models.Console"))
  16. {
  17. Console console = (Console)product;
  18. Make = String.valueOf(console.getMake());
  19. Model = String.valueOf(console.getModel());
  20. Desc = String.valueOf(console.getDescription());
  21. }
  22. else
  23. {
  24. Peripheral peripheral = (Peripheral)product;
  25. Type = String.valueOf(peripheral.getType());
  26. Desc = String.valueOf(peripheral.getDescription());
  27. }
  28.  
  29. try
  30. {
  31. Class.forName(driver);
  32. Connection conn = DriverManager.getConnection(connectionString);
  33. Statement stmt = conn.createStatement();
  34. stmt.executeUpdate("INSERT INTO Products (ProductName, Price, StockLevel, Description, Genre, AttributedConsole, Make, Model, Type) VALUES "
  35. + "('" + product.getProductName() + "','" + product.getPrice() + "','" + product.getStocklevel()
  36. + "','" + Desc + "','" + Genre + "','" + AttConsole +
  37. "','" + Make + "','" + Model + "'," + Type + ")");
  38. //sql statement to add new products to database
  39. conn.close();
  40. return true;
  41. }
  42.  
  43. catch(Exception ex)
  44. {
  45. String message = ex.getMessage();
  46. return false;
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement