Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.01 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.Statement;
  5. import java.util.Date;
  6. import java.util.InputMismatchException;
  7. import java.util.Scanner;
  8. public class Improve {
  9.     private static ResultSet rs;
  10.     private static String Url = "jdbc:mysql://127.0.0.1:3306/improve";
  11.     private static String user = "root";
  12.     private static String pass = "";
  13.     public static void main(String[] args) {
  14.  
  15.  
  16.         try {
  17.             String myDriver = "com.mysql.jdbc.Driver";
  18.             String myUrl = "jdbc:mysql://localhost/improve";
  19.             Class.forName(myDriver);
  20.             Connection conn = DriverManager.getConnection(Url,user,pass);
  21.             Statement st = conn.createStatement();
  22.             String query = "SELECT * From  sale\n" +
  23.                     "LEFT JOIN product \n" +
  24.                     "ON sale.pro_id=product.pro_id \n" +
  25.                     "LEFT JOIN manufacturer\n" +
  26.                     "ON sale.manu_id=manufacturer.manu_id\n" +
  27.                     "LEFT JOIN branch\n" +
  28.                     "ON sale.pro_id=branch.pro_id;";
  29.             ResultSet rs = st.executeQuery(query);
  30.  
  31.             while (rs.next()) {
  32.                 // Get the current value from the result
  33.                 String manu_id = rs.getString("manufacturer.manu_id");
  34.                 String manu_name = rs.getString("manufacturer.manu_name");
  35.                 String pro_id = rs.getString("sale.pro_id");
  36.                 String pro_name = rs.getString("product.pro_name");
  37.                 double pro_price = rs.getDouble("product.pro_price");
  38.                 String branch_name = rs.getString("branch.branch_name");
  39.                 String area_name = rs.getString("branch.area_name");
  40.                 int numofsold = rs.getInt("sale.numofsold");
  41.                 double totalprice = rs.getDouble("sale.totalprice");
  42.                 Date periodtime = rs.getDate("sale.periodtime");
  43.             //    System.out.format("%s,%s,%s,%s,%s,%s,%s,%s,%s, %s\n",  manu_id, manu_name,pro_id,pro_name,pro_price,branch_name,area_name,numofsold,totalprice,periodtime);
  44.             }
  45.             st.close();
  46.         } catch (Exception e) {
  47.             // in case that there is error
  48.         }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.         System.out.println("------------------------------------------------------");
  57.         System.out.println("--------------Company report program------------------");
  58.         System.out.println("Press 1 to view The amount of total sales.");
  59.         System.out.println("Press 2 to view The number of sold items.");
  60.         System.out.println("Press 3 to exit program.");
  61.         System.out.println("------------------------------------------------------");
  62.         Scanner sc = new Scanner(System.in);
  63.  
  64.  
  65.         boolean flag = true;
  66.         while (flag) {
  67.             String number = sc.next();
  68.  
  69.             if (number.equals("1")) {
  70.                 System.out.println("------------------------------------------------------");
  71.                 System.out.println("press 1 to view The amount of total sales at a specific time period");
  72.                 System.out.println("press 2 to view The amount of total sales per manufacturer at a specific time period");
  73.                 System.out.println("press 3 to view The amount of total sales per branch at a specific time period");
  74.                 System.out.println("press 4 to view The amount of total sales per area at a specific time period");
  75.                 System.out.println("press 5 to view The amount of total sales per product type at a specific time period");
  76.                 System.out.println("------------------------------------------------------");
  77.  
  78.  
  79.  
  80.  
  81.           while (flag) {
  82.               String keyboard = sc.next();
  83.               switch (keyboard) {
  84.                   case "1":
  85.                       Improve.caseOne();
  86.                       flag=false;
  87.                       break;
  88.                   case "2":
  89.                       Improve.caseTwo();
  90.                       flag=false;
  91.                       break;
  92.                   case "3":
  93.                       Improve.caseThree();
  94.                       flag=false;
  95.                       break;
  96.                   case "4":
  97.                       Improve.caseFour();
  98.                       flag=false;
  99.                       break;
  100.                   case "5":
  101.                       Improve.caseFive();
  102.                       flag=false;
  103.                       break;
  104.                   default:
  105.                       System.out.println("Please Try again input only number 1,2,3,4,5");
  106.                       flag=true;
  107.  
  108.               }
  109.           }
  110.  
  111.         }else if(number.equals("2")){
  112.                 System.out.println("------------------------------------------------------");
  113.                 System.out.println("press 1 to view The number of sold items at a specific time period");
  114.                 System.out.println("press 2 to view The number of sold items per manufacturer at a specific time period");
  115.                 System.out.println("press 3 to view The number of sold per branch at a specific time period");
  116.                 System.out.println("press 4 to view The number of sold per area at a specific time period");
  117.                 System.out.println("press 5 to view The number of sold  per product type at a specific time period");
  118.                 System.out.println("------------------------------------------------------");
  119.  
  120.  
  121.  
  122.  
  123.                 while (flag) {
  124.                     String keyboard1 = sc.next();
  125.                     switch (keyboard1) {
  126.                         case "1":
  127.                             System.out.println("1");
  128.                             flag=false;
  129.                             break;
  130.                         case "2":
  131.                             System.out.println("2");
  132.                             flag=false;
  133.                             break;
  134.                         case "3":
  135.                             System.out.println("3");
  136.                             flag=false;
  137.                             break;
  138.                         case "4":
  139.                             System.out.println("4");
  140.                             flag=false;
  141.                             break;
  142.                         case "5":
  143.                             System.out.println("5");
  144.                             flag=false;
  145.                             break;
  146.                         default:
  147.                             System.out.println("Please Try again input only number 1,2,3,4,5");
  148.                             flag=true;
  149.  
  150.                     }
  151.                 }
  152.         }else if(number.equals("3")){
  153.             System.exit(0);
  154.         }else{
  155.             System.out.println("Please Try again input only number 1,2,3");
  156.             flag=true;
  157.         }
  158.  
  159.     }
  160.  
  161.  
  162.  
  163. }
  164.     public static void caseOne(){
  165.  
  166. }
  167.     public static void caseTwo(){
  168. //        System.out.format("%s\n",  manu_id);
  169.  
  170.  
  171.     }
  172.     public static void caseThree(){
  173.  
  174.     }
  175.     public static void caseFour(){
  176.  
  177.     }
  178.     public static void caseFive(){
  179.  
  180.     }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement