Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import java.util.Date;
- import java.util.InputMismatchException;
- import java.util.Scanner;
- public class Improve {
- private static ResultSet rs;
- private static String Url = "jdbc:mysql://127.0.0.1:3306/improve";
- private static String user = "root";
- private static String pass = "";
- public static void main(String[] args) {
- try {
- String myDriver = "com.mysql.jdbc.Driver";
- String myUrl = "jdbc:mysql://localhost/improve";
- Class.forName(myDriver);
- Connection conn = DriverManager.getConnection(Url,user,pass);
- Statement st = conn.createStatement();
- String query = "SELECT * From sale\n" +
- "LEFT JOIN product \n" +
- "ON sale.pro_id=product.pro_id \n" +
- "LEFT JOIN manufacturer\n" +
- "ON sale.manu_id=manufacturer.manu_id\n" +
- "LEFT JOIN branch\n" +
- "ON sale.pro_id=branch.pro_id;";
- ResultSet rs = st.executeQuery(query);
- while (rs.next()) {
- // Get the current value from the result
- String manu_id = rs.getString("manufacturer.manu_id");
- String manu_name = rs.getString("manufacturer.manu_name");
- String pro_id = rs.getString("sale.pro_id");
- String pro_name = rs.getString("product.pro_name");
- double pro_price = rs.getDouble("product.pro_price");
- String branch_name = rs.getString("branch.branch_name");
- String area_name = rs.getString("branch.area_name");
- int numofsold = rs.getInt("sale.numofsold");
- double totalprice = rs.getDouble("sale.totalprice");
- Date periodtime = rs.getDate("sale.periodtime");
- // 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);
- }
- st.close();
- } catch (Exception e) {
- // in case that there is error
- }
- System.out.println("------------------------------------------------------");
- System.out.println("--------------Company report program------------------");
- System.out.println("Press 1 to view The amount of total sales.");
- System.out.println("Press 2 to view The number of sold items.");
- System.out.println("Press 3 to exit program.");
- System.out.println("------------------------------------------------------");
- Scanner sc = new Scanner(System.in);
- boolean flag = true;
- while (flag) {
- String number = sc.next();
- if (number.equals("1")) {
- System.out.println("------------------------------------------------------");
- System.out.println("press 1 to view The amount of total sales at a specific time period");
- System.out.println("press 2 to view The amount of total sales per manufacturer at a specific time period");
- System.out.println("press 3 to view The amount of total sales per branch at a specific time period");
- System.out.println("press 4 to view The amount of total sales per area at a specific time period");
- System.out.println("press 5 to view The amount of total sales per product type at a specific time period");
- System.out.println("------------------------------------------------------");
- while (flag) {
- String keyboard = sc.next();
- switch (keyboard) {
- case "1":
- Improve.caseOne();
- flag=false;
- break;
- case "2":
- Improve.caseTwo();
- flag=false;
- break;
- case "3":
- Improve.caseThree();
- flag=false;
- break;
- case "4":
- Improve.caseFour();
- flag=false;
- break;
- case "5":
- Improve.caseFive();
- flag=false;
- break;
- default:
- System.out.println("Please Try again input only number 1,2,3,4,5");
- flag=true;
- }
- }
- }else if(number.equals("2")){
- System.out.println("------------------------------------------------------");
- System.out.println("press 1 to view The number of sold items at a specific time period");
- System.out.println("press 2 to view The number of sold items per manufacturer at a specific time period");
- System.out.println("press 3 to view The number of sold per branch at a specific time period");
- System.out.println("press 4 to view The number of sold per area at a specific time period");
- System.out.println("press 5 to view The number of sold per product type at a specific time period");
- System.out.println("------------------------------------------------------");
- while (flag) {
- String keyboard1 = sc.next();
- switch (keyboard1) {
- case "1":
- System.out.println("1");
- flag=false;
- break;
- case "2":
- System.out.println("2");
- flag=false;
- break;
- case "3":
- System.out.println("3");
- flag=false;
- break;
- case "4":
- System.out.println("4");
- flag=false;
- break;
- case "5":
- System.out.println("5");
- flag=false;
- break;
- default:
- System.out.println("Please Try again input only number 1,2,3,4,5");
- flag=true;
- }
- }
- }else if(number.equals("3")){
- System.exit(0);
- }else{
- System.out.println("Please Try again input only number 1,2,3");
- flag=true;
- }
- }
- }
- public static void caseOne(){
- }
- public static void caseTwo(){
- // System.out.format("%s\n", manu_id);
- }
- public static void caseThree(){
- }
- public static void caseFour(){
- }
- public static void caseFive(){
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement