Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //List<ItemModel> cartItems = new ArrayList<ItemModel>();
- Double price = Double.parseDouble(request.getParameter("price"));
- int quantity = Integer.valueOf(request.getParameter("quantity"));
- System.out.println(quantity);
- System.out.println(price);
- Integer id = Integer.valueOf(request.getParameter("id"));
- String name = request.getParameter("name");
- String details="";
- //cartItems.get(id).add(id, name, price, quantity,details);
- ItemModel cartItems = new ItemModel(id, name, price, quantity, details);
- System.out.println(cartItems.toString());
- List<ItemModel> items = new ArrayList<ItemModel>();
- Connection c = null;
- try
- {
- String url = "jdbc:mysql://localhost/roughdb";
- String username = "root";
- String password = "mypass";
- /* String url = "jdbc:mysql://cs3.calstatela.edu/cs3220stu38";
- String username = "cs3220stu38";
- String password = "w5woPb7Z"; */
- c = DriverManager.getConnection( url, username, password );
- //String sql = "insert into shopping_cart (name, quantity, price, each_total) values (?,?,?,?) where id = ?";
- String sql = "INSERT INTO shopping_cart(id, name, quantity, price, each_total) VALUES(?, ?, ?, ?, ?)";
- PreparedStatement pstmt = c.prepareStatement(sql);
- pstmt.setInt(1, id);
- pstmt.setString(2, name);
- pstmt.setInt(3, quantity);
- pstmt.setDouble(4, price);
- pstmt.setDouble(5, quantity*price);
- pstmt.executeUpdate();
- }
- catch( SQLException e )
- {
- throw new ServletException( e );
- }
- finally
- {
- try
- {
- if( c != null ) c.close();
- }
- catch( SQLException e )
- {
- throw new ServletException( e );
- }
- }
- //response.sendRedirect("Store");
- request.getServletContext().setAttribute("cartItems", cartItems);
- //request.getRequestDispatcher("/ShoppingCart.java").forward(request, response);
- response.sendRedirect("ShoppingCart");
- //return;
- //request.getRequestDispatcher("/WEB-INF/ShoppingCart.jsp").forward(request, response);
- //request.getRequestDispatcher("/WEB-INF/StoreFront.jsp").forward(request, response);
Add Comment
Please, Sign In to add comment