Advertisement
Guest User

Untitled

a guest
Apr 14th, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 34.69 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.*;
  3.  
  4. public class Dbms {
  5.     static int access_type;
  6.    
  7.     static final String jdbcURL = "jdbc:mariadb://classdb2.csc.ncsu.edu:3306/sdharma";
  8.    
  9.     public static void main(String[] args) {
  10.         try {
  11.             Class.forName("org.mariadb.jdbc.Driver");
  12.            
  13.             String user = "sdharma";
  14.             String passwd = "200207505";
  15.            
  16.             Connection conn = null;
  17.             Statement stmt = null;
  18.             ResultSet rs = null;
  19.            
  20.             try {
  21.                 conn = DriverManager.getConnection(jdbcURL, user, passwd);
  22.                 stmt = conn.createStatement();
  23.                
  24.                 // stmt.executeUpdate("DROP TABLE COFFEES ");
  25.                
  26.                 dropTables(stmt);
  27.                 createTables(stmt);
  28.                 populateDemoData(stmt);
  29.                 login();
  30.                 showOperations(stmt);
  31. //                rs = stmt.executeQuery("SELECT COF_NAME, PRICE FROM COFFEES");
  32. //
  33. //                while (rs.next()) {
  34. //                    String s = rs.getString("COF_NAME");
  35. //                    float n = rs.getFloat("PRICE");
  36. //                    System.out.println(s + "  " + n);
  37. //                }
  38.                
  39.             } finally {
  40.                 close(rs);
  41.                 close(stmt);
  42.                 close(conn);
  43.             }
  44.         } catch(Throwable oops) {
  45.             oops.printStackTrace();
  46.         }
  47.     }
  48.    
  49.     static void close(Connection conn) {
  50.         if(conn != null) {
  51.             try { conn.close(); } catch(Throwable whatever) {}
  52.         }
  53.     }
  54.    
  55.     static void close(Statement st) {
  56.         if(st != null) {
  57.             try { st.close(); } catch(Throwable whatever) {}
  58.         }
  59.     }
  60.    
  61.     static void close(ResultSet rs) {
  62.         if(rs != null) {
  63.             try { rs.close(); } catch(Throwable whatever) {}
  64.         }
  65.     }
  66.    
  67.     static void login() {
  68.         Scanner sc = new Scanner(System.in);
  69.         System.out.println("Login as:\n\n");
  70.         System.out.println("1) CEO\n");
  71.         System.out.println("2) Manager\n");
  72.         System.out.println("3) Front Desk Representative\n");
  73.         access_type = sc.nextInt();
  74.         //check if access_type is correct
  75.         //Validate login details?
  76.     }
  77.    
  78.     static void showOperations(Statement stmt) throws Exception {
  79.         switch(access_type) {
  80.             case 1:
  81.                 ceoOperations(stmt);
  82.                 break;
  83.             case 2:
  84.                 mgrOperations(stmt);
  85.                 break;
  86.             case 3:
  87.                 fdrOperations(stmt);
  88.                 break;
  89.             default:
  90.                 System.out.println("Invalid option. Re-enter!\n");        }
  91.     }
  92.    
  93.     static void ceoOperations(Statement stmt) throws Exception {
  94.         Scanner sc = new Scanner(System.in);
  95. //        Runtime.getRuntime().exec("clear");
  96.        
  97.         System.out.println("CEO View\n\n");
  98.         System.out.println("1) Manage hotels\n");
  99.         System.out.println("2) Manage staff\n");
  100.         System.out.println("3) View reports\n");
  101.         int option = sc.nextInt();
  102.         switch(option) {
  103.             case 1:
  104.                 manageHotels(stmt);
  105.                 break;
  106.             case 2:
  107.                 manageStaff(stmt);
  108.                 break;
  109.             case 3:
  110.                 viewReports(stmt);
  111.                 break;
  112.             default:
  113.                 System.out.println("Invalid option. Re-enter!\n");
  114.         }
  115.     }
  116.    
  117.     static void mgrOperations(Statement stmt) throws Exception {
  118.         Scanner sc = new Scanner(System.in);
  119. //        Runtime.getRuntime().exec("clear");
  120.        
  121.         System.out.println("Manager View\n\n");
  122.         System.out.println("1) Manage hotels\n");
  123.         System.out.println("2) Manage staff\n");
  124.         System.out.println("3) View reports\n");
  125.         int option = sc.nextInt();
  126.         switch(option) {
  127.             case 1:
  128.                 manageHotels(stmt);
  129.                 break;
  130.             case 2:
  131.                 manageStaff(stmt);
  132.                 break;
  133.             case 3:
  134.                 viewReports(stmt);
  135.                 break;
  136.             default:
  137.                 System.out.println("Invalid option. Re-enter!\n");
  138.         }
  139.     }
  140.    
  141.     static void fdrOperations(Statement stmt) throws Exception {
  142.         Scanner sc = new Scanner(System.in);
  143. //        Runtime.getRuntime().exec("clear");
  144.        
  145.         System.out.println("Front Desk Representative View\n\n");
  146.         System.out.println("1) Manage customers\n");
  147.         System.out.println("2) Manage room assignment\n");
  148.         System.out.println("3) Manage staff\n");
  149.         System.out.println("4) View reports\n");
  150.         int option = sc.nextInt();
  151.         switch(option) {
  152.             case 1:
  153.                 manageCustomers(stmt);
  154.                 break;
  155.             case 2:
  156.                 assignRoom(stmt);
  157.                 break;
  158.             case 3:
  159.                 manageStaff(stmt);
  160.                 break;
  161.             case 4:
  162.                 viewReports(stmt);
  163.                 break;
  164.             default:
  165.                 System.out.println("Invalid option. Re-enter!\n");
  166.         }
  167.     }
  168.    
  169.     static void manageHotels(Statement stmt) throws Exception {
  170.         Scanner sc = new Scanner(System.in);
  171. //        Runtime.getRuntime().exec("clear");
  172.  
  173.         System.out.println("Manage Hotels\n\n");
  174.         System.out.println("1) Add a new hotel\n");
  175.         System.out.println("2) Delete a hotel\n");
  176.         System.out.println("3) Update hotel's info\n");
  177.         System.out.println("4) Add a new room\n");
  178.         System.out.println("5) Delete a room\n");
  179.         System.out.println("6) Update room info\n");
  180.        
  181.         int option = sc.nextInt();
  182.         switch(option) {
  183.             case 1:
  184.                 addHotel(stmt);
  185.                 break;
  186.             case 2:
  187.                 deleteHotel(stmt);
  188.                 break;
  189.             case 3:
  190.                 updateHotel(stmt);
  191.                 break;
  192.             case 4:
  193.                 addRoom(stmt);
  194.                 break;
  195.             case 5:
  196.                 deleteRoom(stmt);
  197.                 break;
  198.             case 6:
  199.                 updateRoom(stmt);
  200.                 break;
  201.             default:
  202.                 System.out.println("Invalid option. Re-enter!\n");
  203.         }
  204.     }
  205.    
  206.     static void manageStaff(Statement stmt) throws Exception {
  207.         Scanner sc = new Scanner(System.in);
  208.  
  209. //        Runtime.getRuntime().exec("clear");
  210.        
  211.         System.out.println("Manage Staff\n\n");
  212.         System.out.println("1) Add new staff\n");
  213.         System.out.println("2) Delete staff\n");
  214.         System.out.println("3) Update staff's info\n");
  215.         int option = sc.nextInt();
  216.         switch(option) {
  217.             case 1:
  218.                 addStaff(stmt);
  219.                 break;
  220.             case 2:
  221.                 deleteStaff(stmt);
  222.                 break;
  223.             case 3:
  224.                 updateStaff(stmt);
  225.                 break;
  226.             default:
  227.                 System.out.println("Invalid option. Re-enter!\n");
  228.         }
  229.     }
  230.    
  231.     static void manageCustomers(Statement stmt) throws Exception {
  232.         Scanner sc = new Scanner(System.in);
  233.        
  234.         //        Runtime.getRuntime().exec("clear");
  235.        
  236.         System.out.println("Manage Customers\n\n");
  237.         System.out.println("1) Add customer\n");
  238.         System.out.println("2) Delete customer\n");
  239.         System.out.println("3) Update customer's info\n");
  240.         int option = sc.nextInt();
  241.         switch(option) {
  242.             case 1:
  243.                 addCustomer(stmt);
  244.                 break;
  245.             case 2:
  246.                 deleteCustomer(stmt);
  247.                 break;
  248.             case 3:
  249.                 updateCustomer(stmt);
  250.                 break;
  251.             default:
  252.                 System.out.println("Invalid option. Re-enter!\n");
  253.         }
  254.     }
  255.    
  256.     static void viewReports(Statement stmt) throws Exception {
  257. //        Runtime.getRuntime().exec("clear");
  258.        
  259.         System.out.println("View Reports\n\n");
  260.         System.out.println("1) Revenue earned\n");
  261.         System.out.println("2) Delete a hotel\n");
  262.         System.out.println("3) Update hotel's info\n");
  263.     }
  264.    
  265.     static void addHotel(Statement stmt) throws Exception {
  266.         String name, address;
  267.         int phone, mid;
  268.         Scanner sc = new Scanner(System.in);
  269.        
  270.         System.out.println("Add a Hotel\n\n");
  271.         System.out.println("Enter name: ");
  272.         name = sc.nextLine();
  273.         System.out.println("Enter address: ");
  274.         address = sc.nextLine();
  275.         System.out.println("Enter phone: ");
  276.         phone = sc.nextInt();
  277.         System.out.println("Enter manager ID: ");
  278.         mid = sc.nextInt();
  279.        
  280.         //        stmt.executeUpdate("INSERT INTO hotels)
  281.     }
  282.    
  283.     static void deleteHotel(Statement stmt) throws Exception {
  284.         int id;
  285.         Scanner sc = new Scanner(System.in);
  286.        
  287.         System.out.println("Delete a Hotel\n\n");
  288.         System.out.println("Enter ID: ");
  289.         id = sc.nextInt();
  290.        
  291.         //        stmt.executeUpdate("INSERT INTO hotels)
  292.     }
  293.    
  294.     static void updateHotel(Statement stmt) throws Exception {
  295.         String name, address;
  296.         int phone, id, mid;
  297.         Scanner sc = new Scanner(System.in);
  298.        
  299.         System.out.println("Update a Hotel\n\n");
  300.         System.out.println("Enter hotel ID: ");
  301.         id = sc.nextInt();
  302.         System.out.println("Enter new name: ");
  303.         name = sc.nextLine();
  304.         System.out.println("Enter new address: ");
  305.         address = sc.nextLine();
  306.         System.out.println("Enter new phone: ");
  307.         phone = sc.nextInt();
  308.         System.out.println("Enter new manager ID: ");
  309.         mid = sc.nextInt();
  310.        
  311.         //        stmt.executeUpdate("INSERT INTO hotels)
  312.     }
  313.    
  314.     static void addRoom(Statement stmt) throws Exception {
  315.         String name, category;
  316.         int no, hid, occ, availability;
  317.         double price;
  318.        
  319.         Scanner sc = new Scanner(System.in);
  320.        
  321.         System.out.println("Add a Room\n\n");
  322.         System.out.println("Enter hotel ID: ");
  323.         hid = sc.nextInt();
  324.         System.out.println("Enter room number: ");
  325.         no = sc.nextInt();
  326.         System.out.println("Enter category: ");
  327.         category = sc.nextLine();
  328.         System.out.println("Enter max occupancy: ");
  329.         occ = sc.nextInt();
  330.         System.out.println("Enter price: ");
  331.         price = sc.nextDouble();
  332.         System.out.println("Enter availability (0/1): ");
  333.         availability = sc.nextInt();
  334.        
  335.         //        stmt.executeUpdate("INSERT INTO hotels)
  336.     }
  337.    
  338.     static void deleteRoom(Statement stmt) throws Exception {
  339.         int id;
  340.         Scanner sc = new Scanner(System.in);
  341.        
  342.         System.out.println("Delete a Room\n\n");
  343.         System.out.println("Enter ID: ");
  344.         id = sc.nextInt();
  345.        
  346.         //        stmt.executeUpdate("INSERT INTO hotels)
  347.     }
  348.    
  349.     static void updateRoom(Statement stmt) throws Exception {
  350.         String name, category;
  351.         int no, hid, occ, availability;
  352.         double price;
  353.        
  354.         Scanner sc = new Scanner(System.in);
  355.        
  356.         System.out.println("Update a Room\n\n");
  357.         System.out.println("Enter hotel ID: ");
  358.         hid = sc.nextInt();
  359.         System.out.println("Enter room number: ");
  360.         no = sc.nextInt();
  361.         System.out.println("Enter new category: ");
  362.         category = sc.nextLine();
  363.         System.out.println("Enter new max occupancy: ");
  364.         occ = sc.nextInt();
  365.         System.out.println("Enter new price: ");
  366.         price = sc.nextDouble();
  367.         System.out.println("Enter new availability (0/1): ");
  368.         availability = sc.nextInt();
  369.        
  370.         //        stmt.executeUpdate("INSERT INTO hotels)
  371.     }
  372.    
  373.    
  374.    
  375.     static void addStaff(Statement stmt) throws Exception {
  376.         String name, title, department, address;
  377.         int age, phone, availability;
  378.         Scanner sc = new Scanner(System.in);
  379.        
  380.         System.out.println("Add Staff\n\n");
  381.         System.out.println("Enter name: ");
  382.         name = sc.nextLine();
  383.         System.out.println("Enter age: ");
  384.         age = sc.nextInt();
  385.     sc.nextLine();
  386.         System.out.println("Enter title: ");
  387.         title = sc.nextLine();
  388.         System.out.println("Enter department: ");
  389.         department = sc.nextLine();
  390.     sc.nextLine();
  391.         System.out.println("Enter phone: ");
  392.         phone = sc.nextInt();
  393.     sc.nextLine();
  394.         System.out.println("Enter address: ");
  395.         address = sc.nextLine();
  396.         System.out.println("Enter availability (0/1): ");
  397.         availability = sc.nextInt();
  398.         stmt.executeUpdate("INSERT INTO staff (name, age, title, department, phone, address, availability) VALUES (\"" + name + "\"," + age + ",\"" + title + "\",\"" + department + "\"," +         phone + ",\"" + address + "\"," + availability + ")");
  399.     }
  400.    
  401.     static void deleteStaff(Statement stmt) throws Exception {
  402.         int id;
  403.         Scanner sc = new Scanner(System.in);
  404.        
  405.         System.out.println("Delete Staff\n\n");
  406.         System.out.println("Enter ID: ");
  407.         id = sc.nextInt();
  408.         stmt.executeUpdate("delete from staff where id ="+ id);
  409.     }
  410.    
  411.     static void updateStaff(Statement stmt) throws Exception {
  412.         String name, title, dept, address;
  413.         int id, age, phone, availability;
  414.         Scanner sc = new Scanner(System.in);
  415.        
  416.         System.out.println("Update Staff\n\n");
  417.         System.out.println("Enter staff ID: ");
  418.         id = sc.nextInt();
  419.         System.out.println("Enter new name: ");
  420.         name = sc.nextLine();
  421.         System.out.println("Enter new age: ");
  422.         age = sc.nextInt();
  423.         System.out.println("Enter new title: ");
  424.         title = sc.nextLine();
  425.         System.out.println("Enter new department: ");
  426.         dept = sc.nextLine();
  427.         System.out.println("Enter new phone: ");
  428.         phone = sc.nextInt();
  429.         System.out.println("Enter new address: ");
  430.         address = sc.nextLine();
  431.         System.out.println("Enter new availability (0/1): ");
  432.         availability = sc.nextInt();
  433.        
  434.         //        stmt.executeUpdate("INSERT INTO hotels)
  435.     }
  436.    
  437.     static void addCustomer(Statement stmt) throws Exception {
  438.         String name, dob, email;
  439.         int phone, ssn;
  440.         Scanner sc = new Scanner(System.in);
  441.        
  442.         System.out.println("Add Customer\n\n");
  443.         System.out.println("Enter name: ");
  444.         name = sc.nextLine();
  445.         System.out.println("Enter dob: ");
  446.         dob = sc.nextLine();
  447.         System.out.println("Enter phone: ");
  448.         phone = sc.nextInt();
  449.         System.out.println("Enter email: ");
  450.         email = sc.nextLine();
  451.         System.out.println("Enter ssn: ");
  452.         ssn = sc.nextInt();
  453.        
  454.         //        stmt.executeUpdate("INSERT INTO hotels)
  455.     }
  456.    
  457.     static void deleteCustomer(Statement stmt) throws Exception {
  458.         int id;
  459.         Scanner sc = new Scanner(System.in);
  460.        
  461.         System.out.println("Delete Customer\n\n");
  462.         System.out.println("Enter ID: ");
  463.         id = sc.nextInt();
  464.        
  465.         //        stmt.executeUpdate("INSERT INTO hotels)
  466.     }
  467.    
  468.     static void updateCustomer(Statement stmt) throws Exception {
  469.         String name, dob, email;
  470.         int id, phone, ssn;
  471.         Scanner sc = new Scanner(System.in);
  472.        
  473.         System.out.println("Update Customer\n\n");
  474.         System.out.println("Enter customer ID: ");
  475.         id = sc.nextInt();
  476.         System.out.println("Enter name: ");
  477.         name = sc.nextLine();
  478.         System.out.println("Enter dob: ");
  479.         dob = sc.nextLine();
  480.         System.out.println("Enter phone: ");
  481.         phone = sc.nextInt();
  482.         System.out.println("Enter email: ");
  483.         email = sc.nextLine();
  484.         System.out.println("Enter ssn: ");
  485.         ssn = sc.nextInt();
  486.        
  487.         //        stmt.executeUpdate("INSERT INTO hotels)
  488.     }
  489.    
  490.     static void assignRoom(Statement stmt) throws Exception {
  491.         String category, dob, email;
  492.         int hid, cid, phone, ssn;
  493.         ResultSet rs = null;
  494.         Scanner sc = new Scanner(System.in);
  495.        
  496.         System.out.println("Assign Room\n\n");
  497.         System.out.println("Enter hotel ID: ");
  498.         hid = sc.nextInt();
  499.         System.out.println("Enter customer ID: ");
  500.         cid = sc.nextInt();
  501.         System.out.println("Enter room category: ");
  502.         category = sc.nextLine();
  503.        
  504.         String query = "SELECT no FROM rooms WHERE category = " + category + " AND hotel_id = " + hid + " AND is_available = 1";
  505.         rs = stmt.executeQuery(query);
  506.         if(!rs.isBeforeFirst()) {
  507.             System.out.println("No rooms available\n");
  508.         } else {
  509.            
  510.         }
  511.         System.out.println("Enter dob: ");
  512.         dob = sc.nextLine();
  513.         System.out.println("Enter phone: ");
  514.         phone = sc.nextInt();
  515.         System.out.println("Enter email: ");
  516.         email = sc.nextLine();
  517.         System.out.println("Enter ssn: ");
  518.         ssn = sc.nextInt();
  519.        
  520.         //        stmt.executeUpdate("INSERT INTO hotels)
  521.     }
  522.    
  523.     static void dropTables(Statement stmt) throws Exception{
  524.         stmt.executeUpdate("DROP TABLE customer_makes");
  525.         stmt.executeUpdate("DROP TABLE reservation_for");
  526.         stmt.executeUpdate("DROP TABLE staff_works_at");
  527.         stmt.executeUpdate("DROP TABLE staff_provides");
  528.         stmt.executeUpdate("DROP TABLE customers");
  529.         stmt.executeUpdate("DROP TABLE services");
  530.         stmt.executeUpdate("DROP TABLE rooms");
  531.         stmt.executeUpdate("DROP TABLE hotels");
  532.         stmt.executeUpdate("DROP TABLE reservations");
  533.         stmt.executeUpdate("DROP TABLE staff");
  534.     }
  535.    
  536.     static void createTables(Statement stmt) throws Exception{
  537.         // Create the CUSTOMERS table
  538.         stmt.executeUpdate("CREATE TABLE customers (" +
  539.                            "id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, " +
  540.                            "name VARCHAR(128) NOT NULL, " +
  541.                            "dob DATE NOT NULL, " +
  542.                            "phone INT NOT NULL, " +
  543.                            "email VARCHAR(128) NOT NULL, " +
  544.                            "ssn INT NOT NULL UNIQUE)");
  545.        
  546.         // Create the STAFF table
  547.         stmt.executeUpdate("CREATE TABLE staff ( " +
  548.                            "id INT  PRIMARY KEY AUTO_INCREMENT, " +
  549.                            "name VARCHAR(128) NOT NULL, " +
  550.                            "age INT, " +
  551.                            "title VARCHAR(128) NOT NULL, " +
  552.                            "department VARCHAR(128) NOT NULL, " +
  553.                            "phone INT NOT NULL, " +
  554.                            "address VARCHAR(128) NOT NULL, " +
  555.                            "availability TINYINT(1) NOT NULL)");
  556.        
  557.         // Create the HOTELS table
  558.         stmt.executeUpdate("CREATE TABLE hotels (" +
  559.                            "id INT PRIMARY KEY AUTO_INCREMENT, " +
  560.                            "name VARCHAR(128) NOT NULL, " +
  561.                            "address VARCHAR(128) NOT NULL, " +
  562.                            "phone INT NOT NULL, " +
  563.                            "manager_id INT, " +
  564.                            "CONSTRAINT manager_hotel_fk " +
  565.                            "FOREIGN KEY(manager_id) REFERENCES staff(id) " +
  566.                            "ON DELETE CASCADE ON UPDATE CASCADE)");
  567.        
  568.         // Create the ROOMS table
  569.         stmt.executeUpdate("CREATE TABLE rooms (" +
  570.                            "no INT NOT NULL, " +
  571.                            "hotel_id INT NOT NULL, " +
  572.                            "category VARCHAR(128) NOT NULL, " +
  573.                            "max_occupancy INT NOT NULL, " +
  574.                            "price INT NOT NULL, " +
  575.                            "is_available TINYINT(1) NOT NULL, " +
  576.                            "CONSTRAINT hotel_room_fk  " +
  577.                            "FOREIGN KEY(hotel_id) REFERENCES hotels(id)  " +
  578.                            "ON DELETE CASCADE ON UPDATE CASCADE, " +
  579.                            "PRIMARY KEY(no, hotel_id))");
  580.        
  581.         // Create the RESERVATIONS table
  582.         stmt.executeUpdate("CREATE TABLE reservations ( " +
  583.                            "id INT PRIMARY KEY AUTO_INCREMENT, " +
  584.                            "start_date DATE NOT NULL, " +
  585.                            "no_of_guests INT, " +
  586.                            "end_date DATE NOT NULL, " +
  587.                            "check_in_time TIME NOT NULL, " +
  588.                            "check_out_time TIME NOT NULL, " +
  589.                            "total_amount DECIMAL(10,2) NOT NULL, " +
  590.                            "payment_method VARCHAR(128) NOT NULL, " +
  591.                            "card_no BIGINT, " +
  592.                            "expiry DATE, " +
  593.                            "billing_address VARCHAR(128), " +
  594.                            "has_paid TINYINT(1) NOT NULL)");
  595.        
  596.         // Create the SERVICES table
  597.         stmt.executeUpdate("CREATE TABLE services ( " +
  598.                            "id INT AUTO_INCREMENT NOT NULL, " +
  599.                            "reservation_id INT NOT NULL, " +
  600.                            "name VARCHAR(128) NOT NULL, " +
  601.                            "price DECIMAL(10,2) NOT NULL, " +
  602.                            "CONSTRAINT reservation_service_fk " +
  603.                            "FOREIGN KEY(reservation_id) REFERENCES reservations(id) " +
  604.                            "ON DELETE CASCADE ON UPDATE CASCADE, " +
  605.                            "PRIMARY KEY(id, reservation_id))");
  606.        
  607.         // Create the STAFF_WORKS_AT table
  608.         stmt.executeUpdate("CREATE TABLE staff_works_at ( " +
  609.                            "hotel_id INT NOT NULL, " +
  610.                            "staff_id INT NOT NULL, " +
  611.                            "CONSTRAINT staff_works_at_pk PRIMARY KEY(hotel_id, staff_id), " +
  612.                            "CONSTRAINT hotel_staff_works_at_fk " +
  613.                            "FOREIGN KEY(hotel_id) REFERENCES hotels(id) " +
  614.                            "ON DELETE CASCADE ON UPDATE CASCADE, " +
  615.                            "CONSTRAINT staff_works_at_fk " +
  616.                            "FOREIGN KEY(staff_id) REFERENCES staff(id) " +
  617.                            "ON DELETE CASCADE ON UPDATE CASCADE)");
  618.        
  619.         // Create the CUSTOMER_MAKES table
  620.         stmt.executeUpdate("CREATE TABLE customer_makes ( " +
  621.                            "reservation_id INT NOT NULL," +
  622.                            "customer_id INT NOT NULL," +
  623.                            "CONSTRAINT customer_makes_pk PRIMARY KEY(customer_id, reservation_id)," +
  624.                            "CONSTRAINT reservation_customer_makes_fk " +
  625.                            "FOREIGN KEY(reservation_id) REFERENCES reservations(id)" +
  626.                            "ON DELETE CASCADE ON UPDATE CASCADE," +
  627.                            "CONSTRAINT customer_makes_fk " +
  628.                            "FOREIGN KEY(customer_id) REFERENCES customers(id)" +
  629.                            "ON DELETE CASCADE ON UPDATE CASCADE)");
  630.        
  631.         // Create the RESERVATION_FOR table
  632.         stmt.executeUpdate("CREATE TABLE reservation_for ( " +
  633.                            "reservation_id INT NOT NULL, " +
  634.                            "room_no INT NOT NULL, " +
  635.                            "hotel_id INT NOT NULL, " +
  636.                            "CONSTRAINT reservation_for_pk " +
  637.                            "PRIMARY KEY(reservation_id, room_no, hotel_id), " +
  638.                            "CONSTRAINT reservation_for_fk " +
  639.                            "FOREIGN KEY(reservation_id) REFERENCES reservations(id) " +
  640.                            "ON DELETE CASCADE ON UPDATE CASCADE, " +
  641.                            "CONSTRAINT room_reservation_for_fk " +
  642.                            "FOREIGN KEY(room_no,hotel_id) REFERENCES rooms(no,hotel_id) " +
  643.                            "ON DELETE CASCADE ON UPDATE CASCADE)");
  644.        
  645.         // Create the STAFF_PROVIDES table
  646.         stmt.executeUpdate("CREATE TABLE staff_provides ( " +
  647.                            "reservation_id INT NOT NULL, " +
  648.                            "staff_id INT NOT NULL, " +
  649.                            "service_id INT NOT NULL, " +
  650.                            "CONSTRAINT staff_provides_pk " +
  651.                            "PRIMARY KEY(reservation_id, staff_id, service_id), " +
  652.                            "CONSTRAINT staff_provides_fk " +
  653.                            "FOREIGN KEY(staff_id) REFERENCES staff(id)" +
  654.                            "ON DELETE CASCADE ON UPDATE CASCADE, " +
  655.                            "CONSTRAINT service_staff_provides_fk " +
  656.                            "FOREIGN KEY(service_id,reservation_id) REFERENCES services(id,reservation_id) " +
  657.                            "ON DELETE CASCADE ON UPDATE CASCADE)");
  658.     }
  659.    
  660.     static void populateDemoData(Statement stmt) throws Exception{
  661.         //Populate the CUSTOMERS table
  662.         stmt.executeUpdate("INSERT INTO customers (name,dob,phone,email,ssn) " +
  663.                            "VALUES ('David', '1980-01-30', 123, 'david@gmail.com', 5939846)");
  664.        
  665.         stmt.executeUpdate("INSERT INTO customers (name,dob,phone,email,ssn)" +
  666.                            "VALUES ('Sarah', '1971-01-30', 456, 'sarah@gmail.com', 7778352)");
  667.        
  668.         stmt.executeUpdate("INSERT INTO customers (name,dob,phone,email,ssn) " +
  669.                            "VALUES ('Joseph', '1987-01-30', 789, 'joseph@gmail.com', 8589430)");
  670.        
  671.         stmt.executeUpdate("INSERT INTO customers (name,dob,phone,email,ssn)" +
  672.                            "VALUES ('Lucy', '1985-01-30', 213, 'lucy@gmail.com', 4409328)");
  673.        
  674.         //Populate the STAFF table
  675.         stmt.executeUpdate("INSERT INTO staff (name,age,title,department,phone,address,availability) " +
  676.                            "VALUES ('Mary', 40, 'Manager',  'Management', 654, '90 ABC St , Raleigh NC 27', 1)");
  677.        
  678.         stmt.executeUpdate("INSERT INTO staff (name,age,title,department,phone,address,availability)" +
  679.                            "VALUES ('John', 45, 'Manager',  'Management', 564, '798 XYZ St , Rochester NY 54', 1)");
  680.        
  681.         stmt.executeUpdate("INSERT INTO staff (name,age,title,department,phone,address,availability) " +
  682.                            "VALUES ('Carol', 55, 'Manager',  'Management', 564, '351 MH St , Greensboro NC 27', 1)");
  683.        
  684.         stmt.executeUpdate("INSERT INTO staff (name,age,title,department,phone,address,availability)" +
  685.                            "VALUES ('Emma', 55, 'Front Desk Staff',  'Management', 546, '49 ABC St , Raleigh NC 27', 1)");
  686.        
  687.         stmt.executeUpdate("INSERT INTO staff (name,age,title,department,phone,address,availability)" +
  688.                            "VALUES ('Ava', 55, 'Catering Staff',  'Catering', 777, '425 RG St , Raleigh NC 27', 1)");
  689.        
  690.         stmt.executeUpdate("INSERT INTO staff (name,age,title,department,phone,address,availability)" +
  691.                            "VALUES ('Peter', 52, 'Manager',  'Management', 724, '475 RG St , Raleigh NC 27', 1)");
  692.        
  693.         stmt.executeUpdate("INSERT INTO staff (name,age,title,department,phone,address,availability)" +
  694.                            "VALUES ('Olivia', 27, 'Front Desk Staff',  'Management', 799, '325 PD St , Raleigh NC 27', 1)");
  695.        
  696.         // Populate the HOTELS table
  697.         stmt.executeUpdate("INSERT INTO hotels (name,address,phone,manager_id)" +
  698.                            "VALUES ('Hotel A', '21 ABC St , Raleigh NC 27', 919, 1)");
  699.         stmt.executeUpdate("INSERT INTO hotels (name,address,phone,manager_id)" +
  700.                            "VALUES ('Hotel B', '25 XYZ St , Rochester NY 54', 718, 2)");
  701.         stmt.executeUpdate("INSERT INTO hotels (name,address,phone,manager_id)" +
  702.                            "VALUES ('Hotel C', '29 PQR St , Greensboro NC 27', 984, 3)");
  703.         stmt.executeUpdate("INSERT INTO hotels (name,address,phone,manager_id)" +
  704.                            "VALUES ('Hotel D', '28 GHW St , Raleigh NC 32', 920, 6)");
  705.        
  706.         //Populate the ROOMS table
  707.         stmt.executeUpdate("INSERT INTO rooms (no,hotel_id, category, max_occupancy, price, is_available)" +
  708.                            "VALUES ( 1, 1, 'Economy', 1, 100, 1)");
  709.         stmt.executeUpdate("INSERT INTO rooms (no,hotel_id, category, max_occupancy, price, is_available)" +
  710.                            "VALUES ( 2, 1, 'Deluxe', 2, 200, 1)");
  711.         stmt.executeUpdate("INSERT INTO rooms (no,hotel_id, category, max_occupancy, price, is_available)" +
  712.                            "VALUES ( 3, 2, 'Economy', 1, 100, 1)");
  713.         stmt.executeUpdate("INSERT INTO rooms (no,hotel_id, category, max_occupancy, price, is_available)" +
  714.                            "VALUES ( 2, 3, 'Executive', 3, 1000, 0)");
  715.         stmt.executeUpdate("INSERT INTO rooms (no,hotel_id, category, max_occupancy, price, is_available)" +
  716.                            "VALUES ( 1, 4, 'Presidential', 4, 5000, 1)");
  717.         stmt.executeUpdate("INSERT INTO rooms (no,hotel_id, category, max_occupancy, price, is_available)" +
  718.                            "VALUES ( 5, 1, 'Deluxe', 2, 200, 1)");
  719.        
  720.         //Populate the STAFF_WORKS_AT table
  721.         stmt.executeUpdate("INSERT INTO staff_works_at (hotel_id, staff_id)" +
  722.                            "VALUES (1, 1)");
  723.        
  724.         stmt.executeUpdate("INSERT INTO staff_works_at (hotel_id, staff_id)" +
  725.                            "VALUES (2, 2)");
  726.        
  727.         stmt.executeUpdate("INSERT INTO staff_works_at (hotel_id, staff_id)" +
  728.                            "VALUES (3, 3)");
  729.        
  730.         stmt.executeUpdate("INSERT INTO staff_works_at (hotel_id, staff_id)" +
  731.                            "VALUES (1, 4)");
  732.        
  733.         stmt.executeUpdate("INSERT INTO staff_works_at (hotel_id, staff_id)" +
  734.                            "VALUES (1, 5)");
  735.        
  736.         stmt.executeUpdate("INSERT INTO staff_works_at (hotel_id, staff_id)" +
  737.                            "VALUES (4, 6)");
  738.        
  739.         stmt.executeUpdate("INSERT INTO staff_works_at (hotel_id, staff_id)" +
  740.                            "VALUES (4, 7)");
  741.        
  742.         //Populate the RESERVATIONS table
  743.         // no_of_guests start_date  end_date check_in_time check_out_time total_amount payment_method card_no expiry billing_address has_paid
  744.        
  745.         stmt.executeUpdate("INSERT INTO reservations (no_of_guests, start_date,  end_date, check_in_time, check_out_time, total_amount, payment_method, card_no, expiry, billing_address, has_paid)" +
  746.                            "VALUES (1, '2017-05-10', '2017-05-13', '3:17:00', '10:22:00', 0, 'credit', 1052, NULL, '980 TRT St , Raleigh NC', 0)");
  747.        
  748.         stmt.executeUpdate("INSERT INTO reservations (no_of_guests, start_date,  end_date, check_in_time, check_out_time, total_amount, payment_method, card_no, expiry, billing_address, has_paid)" +
  749.                            "VALUES (2, '2017-05-10', '2017-05-13', '4:11:00', '9:27:00', 0, 'credit', 3020, NULL, '7720 MHT St , Greensboro NC', 0)");
  750.        
  751.         stmt.executeUpdate("INSERT INTO reservations (no_of_guests, start_date,  end_date, check_in_time, check_out_time, total_amount, payment_method, card_no, expiry, billing_address, has_paid)" +
  752.                            "VALUES (1, '2016-05-10', '2016-05-14', '3:45:00', '11:10:00', 0, 'credit', 2497, NULL, '231 DRY St , Rochester NY 78', 0)");
  753.        
  754.         stmt.executeUpdate("INSERT INTO reservations (no_of_guests, start_date,  end_date, check_in_time, check_out_time, total_amount, payment_method, card_no, expiry, billing_address, has_paid)" +
  755.                            "VALUES (2, '2018-05-10', '2018-05-12', '2:30:00', '10:00:00', 0, 'cash', NULL, NULL, '24 BST Dr , Dallas TX 14', 0)");
  756.        
  757.         //Populate the RESERVATION_FOR table
  758.         //hotel,room.
  759.         stmt.executeUpdate("INSERT INTO reservation_for (reservation_id, room_no, hotel_id)" +
  760.                            "VALUES (1, 1, 1)");
  761.         stmt.executeUpdate("INSERT INTO reservation_for (reservation_id, room_no, hotel_id)" +
  762.                            "VALUES (2, 2, 1)");
  763.         stmt.executeUpdate("INSERT INTO reservation_for (reservation_id, room_no, hotel_id)" +
  764.                            "VALUES (3, 3, 2)");
  765.         stmt.executeUpdate("INSERT INTO reservation_for (reservation_id, room_no, hotel_id)" +
  766.                            "VALUES (4, 2, 3)");
  767.        
  768.         //Populate the CUSTOMER_MAKES table
  769.         stmt.executeUpdate("INSERT INTO customer_makes (reservation_id, customer_id)" +
  770.                            "VALUES (1, 1)");
  771.         stmt.executeUpdate("INSERT INTO customer_makes (reservation_id, customer_id)" +
  772.                            "VALUES (2, 2)");
  773.         stmt.executeUpdate("INSERT INTO customer_makes (reservation_id, customer_id)" +
  774.                            "VALUES (3, 3)");
  775.         stmt.executeUpdate("INSERT INTO customer_makes (reservation_id, customer_id)" +
  776.                            "VALUES (4, 4)");
  777.        
  778.         //Populate the SERVICES table
  779.         stmt.executeUpdate("INSERT INTO services (reservation_id, name, price)" +
  780.                            "VALUES (1, 'gyms', 15)");
  781.         stmt.executeUpdate("INSERT INTO services (reservation_id, name, price)" +
  782.                            "VALUES (1, 'dry cleaning', 16)");
  783.         stmt.executeUpdate("INSERT INTO services (reservation_id, name, price)" +
  784.                            "VALUES (2, 'gyms', 15)");
  785.         stmt.executeUpdate("INSERT INTO services (reservation_id, name, price)" +
  786.                            "VALUES (3, 'room service', 10)");
  787.         stmt.executeUpdate("INSERT INTO services (reservation_id, name, price)" +
  788.                            "VALUES (4, 'phone bills', 5)");
  789.        
  790.         //Populate the STAFF_PROVIDES table
  791.         //reservation - staffID - serviceID
  792.         stmt.executeUpdate("INSERT INTO staff_provides (reservation_id, staff_id, service_id)" +
  793.                            "VALUES (1, 4, 1)");
  794.         stmt.executeUpdate("INSERT INTO staff_provides (reservation_id, staff_id, service_id)" +
  795.                            "VALUES (1, 5, 2)");
  796.         stmt.executeUpdate("INSERT INTO staff_provides (reservation_id, staff_id, service_id)" +
  797.                            "VALUES (2, 4, 3)");
  798.         stmt.executeUpdate("INSERT INTO staff_provides (reservation_id, staff_id, service_id)" +
  799.                            "VALUES (3, 2, 4)");
  800.         stmt.executeUpdate("INSERT INTO staff_provides (reservation_id, staff_id, service_id)" +
  801.                            "VALUES (4, 3, 5)");
  802.     }
  803. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement