Advertisement
Guest User

processOrder

a guest
Dec 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.13 KB | None | 0 0
  1. <%--
  2.    Document   : processOrder
  3.    Created on : Dec 20, 2017, 6:05:50 AM
  4.    Author     : Sam
  5. --%>
  6.  
  7. <%@page import="java.sql.Statement"%>
  8. <%@page import="java.sql.DriverManager"%>
  9. <%@page import="java.sql.Connection"%>
  10. <%--
  11.    Document   : logout
  12.    Created on : Apr 28, 2017, 9:38:18 PM
  13.    Author     : Sam
  14. --%>
  15.  
  16. <%
  17.    String UserName = "";
  18.    
  19.    if (((String) session.getAttribute("username1")) != null) {
  20.        UserName = (String) session.getAttribute("username1");
  21.      
  22.    }
  23.    
  24.    String order1 = "";
  25.    String qty1 = "";
  26.    
  27.    if ((((String) session.getAttribute("order1")) != null) && (((String) session.getAttribute("qty1")) != null)) {
  28.        order1 = ((String) session.getAttribute("order1"));
  29.        qty1 = ((String) session.getAttribute("qty1"));
  30.    }
  31.  
  32.    String order2 = "";
  33.    String qty2 = "";
  34.    
  35.    if ((((String) session.getAttribute("order2")) != null) && (((String) session.getAttribute("qty2")) != null)) {
  36.        order2 = ((String) session.getAttribute("order2"));
  37.        qty2 = ((String) session.getAttribute("qty2"));
  38.    }
  39.  
  40.  
  41.    String order3 = "";
  42.    String qty3 = "";
  43.    
  44.    if ((((String) session.getAttribute("order3")) != null) && (((String) session.getAttribute("qty3")) != null)) {
  45.        order3 = ((String) session.getAttribute("order3"));
  46.        qty3 = ((String) session.getAttribute("qty3"));
  47.    }
  48.  
  49.    
  50.    String order4 = "";
  51.    String qty4 = "";
  52.  
  53.    if ((((String) session.getAttribute("order4")) != null) && (((String) session.getAttribute("qty4")) != null)) {
  54.        order4 = ((String) session.getAttribute("order4"));
  55.        qty4 = ((String) session.getAttribute("qty4"));
  56.    }
  57.  
  58.    
  59.    String order5 = "";
  60.    String qty5 = "";
  61.  
  62.    if ((((String) session.getAttribute("order5")) != null) && (((String) session.getAttribute("qty5")) != null)) {
  63.        order5 = ((String) session.getAttribute("order5"));
  64.        qty5 = ((String) session.getAttribute("qty5"));
  65.    }
  66.  
  67.    
  68.    String order6 = "";
  69.    String qty6 = "";
  70.  
  71.    if ((((String) session.getAttribute("order6")) != null) && (((String) session.getAttribute("qty6")) != null)) {
  72.        order6 = ((String) session.getAttribute("order6"));
  73.        qty6 = ((String) session.getAttribute("qty6"));
  74.    }
  75.  
  76.    
  77.    String order7 = "";
  78.    String qty7 = "";
  79.  
  80.    if ((((String) session.getAttribute("order7")) != null) && (((String) session.getAttribute("qty7")) != null)) {
  81.        order7 = ((String) session.getAttribute("order7"));
  82.        qty7 = ((String) session.getAttribute("qty7"));
  83.    }
  84.  
  85.    
  86.    String order8 = "";
  87.    String qty8 = "";
  88.  
  89.    if ((((String) session.getAttribute("order8")) != null) && (((String) session.getAttribute("qty8")) != null)) {
  90.        order8 = ((String) session.getAttribute("order8"));
  91.        qty8 = ((String) session.getAttribute("qty8"));
  92.    }
  93.  
  94.    
  95.    String order9 = "";
  96.    String qty9 = "";
  97.  
  98.    if ((((String) session.getAttribute("order9")) != null) && (((String) session.getAttribute("qty9")) != null)) {
  99.        order9 = ((String) session.getAttribute("order9"));
  100.        qty9 = ((String) session.getAttribute("qty9"));
  101.    }
  102.  
  103.    
  104.    String order10 = "";
  105.    String qty10 = "";
  106.  
  107.    if ((((String) session.getAttribute("order10")) != null) && (((String) session.getAttribute("qty10")) != null)) {
  108.        order10 = ((String) session.getAttribute("order10"));
  109.        qty10 = ((String) session.getAttribute("qty10"));
  110.    }
  111.  
  112.  
  113.    Connection connection = null;
  114.    String status = "Pending";
  115.  
  116.    try {
  117.  
  118.        Class.forName("org.gjt.mm.mysql.Driver");
  119.        String url = "jdbc:mysql://localhost/dbburgenator";
  120.        String user = "root";
  121.        String pwd = "";
  122.  
  123.        connection = DriverManager.getConnection(url, user, pwd);
  124.        Statement statement = connection.createStatement();
  125.  
  126.        //INSERT DATA TO TABLE order.
  127.        String queryInsert1 = "INSERT INTO orders "
  128.                + "(userName, order1, qty1, order2, qty2, order3, qty3, order4, qty4, order5, qty5, order6, qty6, order7, qty7, order8, qty8, order9, qty9, order10, qty10, status)"
  129.                + "VALUES "
  130.                + "('" + UserName + "', '" + order1 + "', '" + qty1 + "', '" + order2 + "', '" + qty2 + "', '" + order3 + "', '" + qty3 + "', '" + order4 + "', '" + qty4 + "', '" + order5 + "', '" + qty5 + "', '" + order6 + "', '" + qty6 + "', '" + order7 + "', '" + qty7 + "', '" + order8 + "', '" + qty8 + "', '" + order9 + "', '" + qty9 + "', '" + order10 + "', '" + qty10 + "', '" + status + "')";
  131.  
  132.        int i = statement.executeUpdate(queryInsert1);
  133.  
  134.        if (i == 1) {
  135.            out.println("<script>alert('ORDER PROCESSED!!! ');document.location.href='index.jsp';</script>");
  136.         } else {
  137.             out.println("<script>alert('ORDER FAIL TO PROCESSED!!! ');window.history.back();</script>");
  138.         }
  139.  
  140.         if (connection != null) {
  141.             connection.close();
  142.         }
  143.     } catch (Exception e) {
  144.         out.println("Error" + e);
  145.         System.out.println("Error" + e);
  146.  
  147.     } finally {
  148.         if (null != connection) {
  149.             connection.close();
  150.         }
  151.     }
  152. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement