Guest User

Untitled

a guest
Jan 27th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 23.42 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.sql.*;
  5. import java.util.Scanner;
  6.  
  7. public class Connect_to_SQL {
  8.     static Scanner in1 = new Scanner(System.in);
  9.    
  10.     public static void CleanUp(){
  11.         in1.close();
  12.     }
  13.    
  14.     //display the tables
  15.     public static void displayPerson(){
  16.         //Connect to SQL
  17.         try{
  18.             Class.forName("com.mysql.jdbc.Driver");
  19.             Connection c1 = null;
  20.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  21.             Statement s1 = c1.createStatement();
  22.             ResultSet rs = s1.executeQuery("SELECT * FROM Person");
  23.             System.out.println("Person Database");
  24.             System.out.println("-------------------------------------");
  25.             while(rs.next()){
  26.                 String Person_ID = rs.getString(1);
  27.                 String First_Name = rs.getString(2);
  28.                 String Last_Name = rs.getString(3);
  29.                 String DOB = rs.getString(4);
  30.                 String Role = rs.getString(5);
  31.                 System.out.println(Person_ID + " " + First_Name + " " + Last_Name + " " + DOB + " " + Role);
  32.             }
  33.             c1.close();
  34.         }catch(Exception e){ System.out.println(e);}
  35.     }
  36.    
  37.     public static void displayMovies(){
  38.         //Connect to SQL
  39.             try{
  40.                 Class.forName("com.mysql.jdbc.Driver");
  41.                 Connection c1 = null;
  42.                 c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  43.                 Statement s1 = c1.createStatement();
  44.                 ResultSet rs = s1.executeQuery("SELECT * FROM Movies");
  45.                 System.out.println("Movie Database");
  46.                 System.out.println("-------------------------------------");
  47.                 while(rs.next()){
  48.                     String Movie_ID = rs.getString(1);
  49.                     String Title = rs.getString(2);
  50.                     String Year = rs.getString(3);
  51.                     String Genre = rs.getString(4);
  52.                     System.out.println(Movie_ID + " " + Title + " " + Year + " " + Genre);
  53.                     }
  54.                     c1.close();
  55.                 }catch(Exception e){ System.out.println(e);}
  56.     }
  57.    
  58.     public static void displayActs_In(){
  59.         //Connect to SQL
  60.         try{
  61.             Class.forName("com.mysql.jdbc.Driver");
  62.             Connection c1 = null;
  63.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  64.             Statement s1 = c1.createStatement();
  65.             ResultSet rs = s1.executeQuery("SELECT * FROM Acts_In");
  66.             System.out.println("Acts_In Database");
  67.             System.out.println("-------------------------------------");
  68.             while(rs.next()){
  69.                 String Person_ID = rs.getString(1);
  70.                 String Movie_ID = rs.getString(2);
  71.                 System.out.println(Person_ID + " " + Movie_ID );
  72.                 }
  73.                 c1.close();
  74.             }catch(Exception e){ System.out.println(e);}
  75.     }
  76.    
  77.     public static void displayDirects_In(){
  78.         //Connect to SQL
  79.         try{
  80.             Class.forName("com.mysql.jdbc.Driver");
  81.             Connection c1 = null;
  82.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  83.             Statement s1 = c1.createStatement();
  84.             ResultSet rs = s1.executeQuery("SELECT * FROM Directs_In");
  85.             System.out.println("Directs_In Database");
  86.             System.out.println("-------------------------------------");
  87.             while(rs.next()){
  88.                 String Person_ID = rs.getString(1);
  89.                 String Movie_ID = rs.getString(2);
  90.                 System.out.println(Person_ID + " " + Movie_ID );
  91.                 }
  92.                 c1.close();
  93.             }catch(Exception e){ System.out.println(e);}
  94.        
  95.     }
  96.    
  97.     //display the dynamic queries
  98.     public static void displayDQuery1(){
  99.         //Connect to SQL
  100.         try{
  101.             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  102.             System.out.println("Enter the first name of the actor for which you wish to fire the queries:");
  103.             String fname = br.readLine();
  104.             System.out.println("Enter the last name of the actor for which you wish to fire the queries:");
  105.             String lname = br.readLine();
  106.            
  107.             Class.forName("com.mysql.jdbc.Driver");
  108.             Connection c1 = null;
  109.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  110.             Statement s1 = c1.createStatement();
  111.             ResultSet rs = s1.executeQuery("SELECT Title FROM Movies WHERE Movie_ID IN (SELECT Acts_In.Movie_ID FROM Acts_In, Person WHERE Person.First_Name = '" + fname + "' "
  112.                      + "AND Person.Last_Name = '" + lname + "' "
  113.                      + "AND (Person.Job = 'Actor' OR Person.Job = 'Both') AND Person.Person_ID = Acts_In.Person_ID);");
  114.             System.out.println("The List of Movies are as follows: ");
  115.             while(rs.next()){
  116.                 String Title = rs.getString(1);
  117.                 System.out.println(Title);
  118.             }
  119.             c1.close();
  120.             }catch(Exception e){ System.out.println(e);}           
  121.     }
  122.     public static void displayDQuery2(){
  123.         //Connect to SQL
  124.         try{
  125.             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  126.             System.out.println("Enter the first name of the actor for which you wish to fire the queries:");
  127.             String fname = br.readLine();
  128.             System.out.println("Enter the last name of the actor for which you wish to fire the queries:");
  129.             String lname = br.readLine();
  130.            
  131.             Class.forName("com.mysql.jdbc.Driver");
  132.             Connection c1 = null;
  133.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  134.             Statement s1 = c1.createStatement();
  135.             ResultSet rs = s1.executeQuery("SELECT Title FROM Movies WHERE Movie_ID IN (SELECT Movie_ID FROM"
  136.                     + "(SELECT * FROM Acts_In NATURAL JOIN Person WHERE Person.First_Name = '" + fname + "' "
  137.                     + "AND Person.Last_Name = '" + lname + "' " + " AND Job = 'Both') AS S NATURAL JOIN Directs_In);");
  138.             System.out.println("The List of Movies are as follows: ");
  139.             while(rs.next()){
  140.                 String Title = rs.getString(1);
  141.                 System.out.println(Title);
  142.             }
  143.             c1.close();
  144.             }catch(Exception e){ System.out.println(e);}           
  145.     }
  146.    
  147.     public static void displayDQuery3(){
  148.         //Connect to SQL
  149.         try{
  150.             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  151.             System.out.println("Enter the first name of the actor for which you wish to fire the queries:");
  152.             String fname = br.readLine();
  153.             System.out.println("Enter the last name of the actor for which you wish to fire the queries:");
  154.             String lname = br.readLine();
  155.            
  156.             Class.forName("com.mysql.jdbc.Driver");
  157.             Connection c1 = null;
  158.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  159.             Statement s1 = c1.createStatement();
  160.             ResultSet rs = s1.executeQuery("SELECT Title FROM Movies WHERE Movie_ID IN "
  161.                     + "(SELECT Acts_In.Movie_ID FROM Acts_In, Person "
  162.                     + "WHERE Person.First_Name = '" + fname + "' " + "AND Person.Last_Name = '" + lname + "' "
  163.                     + "AND (Person.Job = 'Actor' OR Person.Job = 'Both') "
  164.                     + "AND Person.Person_ID =  Acts_In.Person_ID) AND Year >= 2000 AND Genre = 'Thriller';");
  165.             System.out.println("The list of movies are as follows:");
  166.             while(rs.next()){
  167.                 String Title = rs.getString(1);
  168.                 System.out.println(Title);
  169.             }
  170.             c1.close();
  171.             }catch(Exception e){ System.out.println(e);}           
  172.     }
  173.  
  174.     public static void displayDQuery4(){
  175.         //Connect to SQL
  176.         try{
  177.             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  178.             System.out.println("Enter the first name of the actor for which you wish to fire the queries:");
  179.             String fname = br.readLine();
  180.             System.out.println("Enter the last name of the actor for which you wish to fire the queries:");
  181.             String lname = br.readLine();
  182.            
  183.             Class.forName("com.mysql.jdbc.Driver");
  184.             Connection c1 = null;
  185.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  186.             Statement s1 = c1.createStatement();
  187.             ResultSet rs = s1.executeQuery("SELECT S3.First_Name, S3.Last_Name FROM "
  188.                     + "(SELECT DISTINCT Person_ID FROM (SELECT Movie_ID FROM Person NATURAL JOIN Acts_In "
  189.                     + "WHERE First_Name = '" + fname + "' " + " AND Last_Name = '" + lname + "' " + " AND "
  190.                     + "(Person.Job = 'Actor' OR Person.Job = 'Both')) AS S1 NATURAL JOIN Acts_In) "
  191.                     + "AS S2 NATURAL JOIN Person AS S3, Person "
  192.                     + "WHERE Person.First_Name = '" + fname + "' " + " AND Person.Last_Name = '" + lname + "' "
  193.                     + "AND (Person.Job = 'Actor' OR Person.Job = 'Both') "
  194.                     + "AND S3.DOB >= date_add(Person.DOB, INTERVAL 10 year);");
  195.             System.out.println("The list of all co actors are as follows:");
  196.             while(rs.next()){
  197.                 String First = rs.getString(1);
  198.                 String Last = rs.getString(1);
  199.                 System.out.println(First + " " + Last);
  200.             }
  201.             c1.close();
  202.             }catch(Exception e){ System.out.println(e);}           
  203.     }
  204.  
  205.     public static void displayDQuery5(){
  206.         //Connect to SQL
  207.         try{
  208.             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  209.             System.out.println("Enter the first name of the actor for which you wish to fire the queries:");
  210.             String fname = br.readLine();
  211.             System.out.println("Enter the last name of the actor for which you wish to fire the queries:");
  212.             String lname = br.readLine();
  213.            
  214.             Class.forName("com.mysql.jdbc.Driver");
  215.             Connection c1 = null;
  216.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  217.             Statement s1 = c1.createStatement();
  218.             ResultSet rs = s1.executeQuery("SELECT First_Name, Last_Name  FROM (SELECT Person_ID, Max(c) AS Maxc FROM ( SELECT Person_ID, count(Person_ID) c  FROM (SELECT Person_ID  FROM (SELECT Movie_ID FROM Person NATURAL JOIN Acts_In  WHERE First_Name = '" + fname + "' " + " AND Last_Name = '" + lname + "' " + " AND (Person.Job = 'Actor' OR Person.Job = 'Both')) AS S1 NATURAL JOIN Directs_In) AS S1 GROUP BY Person_ID) AS S2 NATURAL JOIN Person GROUP BY Person_ID) AS S3 NATURAL JOIN Person  WHERE Maxc IN (SELECT Max(c) AS Maxc  FROM (SELECT Person_ID, count(Person_ID) c  FROM (SELECT Person_ID  FROM (SELECT Movie_ID FROM Person NATURAL JOIN Acts_In  WHERE First_Name = '" + fname + "' " + " AND Last_Name = '" + lname + "' " + " AND (Person.Job = 'Actor' OR Person.Job = 'Both')) AS S1 NATURAL JOIN Directs_In) AS S1 GROUP BY Person_ID) AS S2 NATURAL JOIN Person);");
  219.             System.out.println("The name of the director is as follows:");
  220.             while(rs.next()){
  221.                 String First = rs.getString(1);
  222.                 String Last = rs.getString(2);
  223.                 System.out.println(First + " " + Last);
  224.             }
  225.             c1.close();
  226.             }catch(Exception e){ System.out.println(e);}           
  227.     }
  228.  
  229.     //display static queries
  230.     public static void displaySQuery1(){
  231.         //Connect to SQL
  232.         try{
  233.             Class.forName("com.mysql.jdbc.Driver");
  234.             Connection c1 = null;
  235.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  236.             Statement s1 = c1.createStatement();
  237.             ResultSet rs = s1.executeQuery("SELECT Title FROM Movies WHERE Movie_ID IN (SELECT Acts_In.Movie_ID FROM Acts_In, Person WHERE Person.First_Name = \'Sharukh\'"
  238.                      + "AND Person.Last_Name = \'Khan\'"
  239.                      + "AND (Person.Job = 'Actor' OR Person.Job = 'Both') AND Person.Person_ID = Acts_In.Person_ID);");
  240.             System.out.println("The List of Movies are as follows: ");
  241.             while(rs.next()){
  242.                 String Title = rs.getString(1);
  243.                 System.out.println(Title);
  244.             }
  245.             c1.close();
  246.             }catch(Exception e){ System.out.println(e);}           
  247.     }
  248.    
  249.     public static void displaySQuery2(){
  250.         //Connect to SQL
  251.         try{
  252.             Class.forName("com.mysql.jdbc.Driver");
  253.             Connection c1 = null;
  254.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  255.             Statement s1 = c1.createStatement();
  256.             ResultSet rs = s1.executeQuery("SELECT Title FROM Movies WHERE Movie_ID IN (SELECT Movie_ID FROM"
  257.                     + "(SELECT * FROM Acts_In NATURAL JOIN Person WHERE Person.First_Name = 'Sharukh' "
  258.                     + "AND Person.Last_Name = 'Khan' AND Job = 'Both') AS S NATURAL JOIN Directs_In);");
  259.             System.out.println("The List of Movies are as follows: ");
  260.             while(rs.next()){
  261.                 String Title = rs.getString(1);
  262.                 System.out.println(Title);
  263.             }
  264.             c1.close();
  265.             }catch(Exception e){ System.out.println(e);}           
  266.     }
  267.  
  268.     public static void displaySQuery3(){
  269.         //Connect to SQL
  270.         try{
  271.             Class.forName("com.mysql.jdbc.Driver");
  272.             Connection c1 = null;
  273.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  274.             Statement s1 = c1.createStatement();
  275.             ResultSet rs = s1.executeQuery("SELECT Title FROM Movies WHERE Movie_ID IN "
  276.                     + "(SELECT Acts_In.Movie_ID FROM Acts_In, Person "
  277.                     + "WHERE Person.First_Name = 'Sharukh' AND Person.Last_Name = 'Khan' "
  278.                     + "AND (Person.Job = 'Actor' OR Person.Job = 'Both') "
  279.                     + "AND Person.Person_ID =  Acts_In.Person_ID) AND Year >= 2000 AND Genre = 'Thriller';");
  280.             System.out.println("The list of movies are as follows:");
  281.             while(rs.next()){
  282.                 String Title = rs.getString(1);
  283.                 System.out.println(Title);
  284.             }
  285.             c1.close();
  286.             }catch(Exception e){ System.out.println(e);}           
  287.     }
  288.  
  289.     public static void displaySQuery4(){
  290.         //Connect to SQL
  291.         try{
  292.             Class.forName("com.mysql.jdbc.Driver");
  293.             Connection c1 = null;
  294.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  295.             Statement s1 = c1.createStatement();
  296.             ResultSet rs = s1.executeQuery("SELECT S3.First_Name, S3.Last_Name FROM "
  297.                     + "(SELECT DISTINCT Person_ID FROM (SELECT Movie_ID FROM Person NATURAL JOIN Acts_In "
  298.                     + "WHERE First_Name = 'Sharukh' AND Last_Name = 'Khan' AND "
  299.                     + "(Person.Job = 'Actor' OR Person.Job = 'Both')) AS S1 NATURAL JOIN Acts_In) "
  300.                     + "AS S2 NATURAL JOIN Person AS S3, Person "
  301.                     + "WHERE Person.First_Name = 'Sharukh' AND Person.Last_Name = 'Khan' "
  302.                     + "AND (Person.Job = 'Actor' OR Person.Job = 'Both') "
  303.                     + "AND S3.DOB >= date_add(Person.DOB, INTERVAL 10 year);");
  304.             System.out.println("The list of all co actors are as follows:");
  305.             while(rs.next()){
  306.                 String First = rs.getString(1);
  307.                 String Last = rs.getString(1);
  308.                 System.out.println(First + " " + Last);
  309.             }
  310.             c1.close();
  311.             }catch(Exception e){ System.out.println(e);}           
  312.     }
  313.  
  314.     public static void displaySQuery5(){
  315.         //Connect to SQL
  316.         try{
  317.             Class.forName("com.mysql.jdbc.Driver");
  318.             Connection c1 = null;
  319.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  320.             Statement s1 = c1.createStatement();
  321.             ResultSet rs = s1.executeQuery("SELECT First_Name, Last_Name  FROM (SELECT Person_ID, Max(c) AS Maxc FROM ( SELECT Person_ID, count(Person_ID) c  FROM (SELECT Person_ID  FROM (SELECT Movie_ID FROM Person NATURAL JOIN Acts_In  WHERE First_Name = 'Sharukh' AND Last_Name = 'Khan' AND (Person.Job = 'Actor' OR Person.Job = 'Both')) AS S1 NATURAL JOIN Directs_In) AS S1 GROUP BY Person_ID) AS S2 NATURAL JOIN Person GROUP BY Person_ID) AS S3 NATURAL JOIN Person  WHERE Maxc IN (SELECT Max(c) AS Maxc  FROM (SELECT Person_ID, count(Person_ID) c  FROM (SELECT Person_ID  FROM (SELECT Movie_ID FROM Person NATURAL JOIN Acts_In  WHERE First_Name = 'Sharukh' AND Last_Name = 'Khan' AND (Person.Job = 'Actor' OR Person.Job = 'Both')) AS S1 NATURAL JOIN Directs_In) AS S1 GROUP BY Person_ID) AS S2 NATURAL JOIN Person);");
  322.             System.out.println("The name of the director is as follows:");
  323.             while(rs.next()){
  324.                 String First = rs.getString(1);
  325.                 String Last = rs.getString(2);
  326.                 System.out.println(First + " " + Last);
  327.             }
  328.             c1.close();
  329.             }catch(Exception e){ System.out.println(e);}           
  330.     }
  331.  
  332.     public static void fireStaticQueries() throws IOException{
  333.         int menu_option;
  334.         String cont;
  335.         do{
  336.             System.out.println("-------------Static Queries Menu---------------");
  337.             System.out.println("Enter 1 to display list of all the films in which an actor with first name \"Sharukh\" and last name \"Khan\" acted");
  338.             System.out.println("Enter 2 to display list of all movies for which \"Sharukh\" \"Khan\" was an actor as well as director");
  339.             System.out.println("Enter 3 to display list of all \"Thrillers\" released after the year 2000 in which \"Sharukh\" \"Khan\" acted.");
  340.             System.out.println("Enter 4 to display List all Co-actors of \"Sharukh\" \"Khan\" who are younger than him by 10 years");
  341.             System.out.println("Enter 5 to display the Director in whose movie \"Sharukh\" \"Khan\" acted most number of times");
  342.             menu_option = in1.nextInt();
  343.            
  344.             if(menu_option == 1){
  345.                 displaySQuery1();
  346.             }
  347.             else if(menu_option == 2){
  348.                 displaySQuery2();
  349.             }
  350.             else if(menu_option == 3){
  351.                 displaySQuery3();
  352.             }
  353.             else if(menu_option == 4){
  354.                 displaySQuery4();
  355.             }
  356.             else if(menu_option == 5){
  357.                 displaySQuery5();
  358.             }
  359.             else{
  360.                 System.out.println("You have entered a wrong choice");
  361.             }
  362.  
  363.             //Scanner in2 = new Scanner(System.in);
  364.             System.out.println("Do you wish to continue(yes/no)");
  365.             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  366.             cont = br.readLine();
  367.            
  368.         }while(cont.equals("yes"));
  369.         System.out.println("Returning to the main menu...");
  370.         System.out.println("--------------------------------------------------------------");
  371.     }
  372.  
  373.     public static void fireDynamicQueries() throws IOException{
  374.         int menu_option;
  375.         String cont;
  376.         do{
  377.             System.out.println("-------------Dynamic Queries Menu---------------");
  378.             System.out.println("Enter 1 to display list of all the films in which an actor acted");
  379.             System.out.println("Enter 2 to display list of all movies for which an actor was an actor as well as director");
  380.             System.out.println("Enter 3 to display list of all \"Thrillers\" released after the year 2000 in which an actor acted.");
  381.             System.out.println("Enter 4 to display List all Co-actors of an actor who are younger than him by 10 years");
  382.             System.out.println("Enter 5 to display the Director in whose movie an actor acted most number of times");
  383.             menu_option = in1.nextInt();
  384.            
  385.             if(menu_option == 1){
  386.                 displayDQuery1();
  387.             }
  388.             else if(menu_option == 2){
  389.                 displayDQuery2();
  390.             }
  391.             else if(menu_option == 3){
  392.                 displayDQuery3();
  393.             }
  394.             else if(menu_option == 4){
  395.                 displayDQuery4();
  396.             }
  397.             else if(menu_option == 5){
  398.                 displayDQuery5();
  399.             }
  400.             else{
  401.                 System.out.println("You have entered a wrong choice");
  402.             }
  403.             //Scanner in2 = new Scanner(System.in);
  404.             System.out.println("Do you wish to continue(yes/no)");
  405.             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  406.             cont = br.readLine();
  407.            
  408.         }while(cont.equals("yes"));
  409.         System.out.println("Returning to the main menu...");
  410.         System.out.println("--------------------------------------------------------------");
  411.     }
  412.  
  413.     //insert queries
  414.     public static void insertPerson(){
  415.         try{
  416.             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  417.             System.out.println("Enter the first name of the actor for which you wish to fire the queries:");
  418.             String fname = br.readLine();
  419.             System.out.println("Enter the last name of the actor for which you wish to fire the queries:");
  420.             String lname = br.readLine();
  421.             System.out.println("Enter the DOB of the actor for which you wish to fire the queries:");
  422.             String dob = br.readLine();
  423.             System.out.println("Enter the role of the actor for which you wish to fire the queries:(1/2/3)");
  424.             String role = br.readLine();
  425.            
  426.             Class.forName("com.mysql.jdbc.Driver");
  427.             Connection c1 = null;
  428.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  429.             Statement s1 = c1.createStatement();
  430.             s1.executeUpdate("INSERT INTO Person VALUES(null,'" + fname + "' " + ", '" + lname + "' " + ",'" + dob + "' " + ", " + role + ");");
  431.            
  432.             c1.close();
  433.             }catch(Exception e){ System.out.println(e);}
  434.     }
  435.    
  436.     public static void insertMovies(){
  437.         try{
  438.             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  439.             System.out.println("Enter the title of the movie for which you wish to fire the queries:");
  440.             String title = br.readLine();
  441.             System.out.println("Enter the year of the movie for which you wish to fire the queries:");
  442.             String year = br.readLine();
  443.             System.out.println("Enter the genre of the movie for which you wish to fire the queries:");
  444.             String genre = br.readLine();
  445.            
  446.             Class.forName("com.mysql.jdbc.Driver");
  447.             Connection c1 = null;
  448.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  449.             Statement s1 = c1.createStatement();
  450.             s1.executeUpdate("INSERT INTO Movies VALUES(null,'" + title + "' " + ", '" + year + "' " + ",'" + genre + "' " + ");");
  451.            
  452.             c1.close();
  453.             }catch(Exception e){ System.out.println(e);}
  454.     }
  455.    
  456.     public static void insertActs_In(){
  457.         try{
  458.             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  459.             System.out.println("Enter the Person_ID for which you wish to fire the queries:");
  460.             String p = br.readLine();
  461.             System.out.println("Enter the Movie_ID for which you wish to fire the queries:");
  462.             String m = br.readLine();
  463.            
  464.             Class.forName("com.mysql.jdbc.Driver");
  465.             Connection c1 = null;
  466.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  467.             Statement s1 = c1.createStatement();
  468.             s1.executeUpdate("INSERT INTO Acts_In VALUES('" + p + "' " + ", '" + m + "' " + ");");
  469.            
  470.             c1.close();
  471.             }catch(Exception e){ System.out.println(e);}
  472.     }
  473.    
  474.     public static void insertDirects_In(){
  475.         try{
  476.             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  477.             System.out.println("Enter the Person_ID for which you wish to fire the queries:");
  478.             String p = br.readLine();
  479.             System.out.println("Enter the Movie_ID for which you wish to fire the queries:");
  480.             String m = br.readLine();
  481.            
  482.             Class.forName("com.mysql.jdbc.Driver");
  483.             Connection c1 = null;
  484.             c1 = DriverManager.getConnection("jdbc:mysql://10.5.18.68/13CS30041","13CS30041", "cse12");
  485.             Statement s1 = c1.createStatement();
  486.             s1.executeUpdate("INSERT INTO Directs_In VALUES('" + p + "' " + ", '" + m + "' " + ");");
  487.            
  488.             c1.close();
  489.             }catch(Exception e){ System.out.println(e);}
  490.     }
  491.    
  492.     //main
  493.     public static void main(String[] args) throws IOException {
  494.         // TODO Auto-generated method stub
  495.         //System.out.println("Hello!");
  496.         int menu_option;
  497.         String cont;
  498.         do{
  499.             System.out.println("-------------Menu---------------");
  500.             System.out.println("Enter 1 to display Person Table");
  501.             System.out.println("Enter 2 to display Movies Table");
  502.             System.out.println("Enter 3 to display Acts_In Table");
  503.             System.out.println("Enter 4 to display Directs_In Table");
  504.             System.out.println("Enter 5 to fire Static Queries");
  505.             System.out.println("Enter 6 to fire Dynamic Queries");
  506.             System.out.println("Enter 7 to insert into Person Table");
  507.             System.out.println("Enter 8 to insert into Movies Table");
  508.             System.out.println("Enter 9 to insert into Acts_In Table");
  509.             System.out.println("Enter 10 to insert into Directs_In Table");
  510.            
  511.             menu_option = in1.nextInt();
  512.             //in1.close();
  513.            
  514.             if(menu_option == 1){
  515.                 displayPerson();
  516.             }
  517.             else if(menu_option == 2){
  518.                 displayMovies();
  519.             }
  520.             else if(menu_option == 3){
  521.                 displayActs_In();
  522.             }
  523.             else if(menu_option == 4){
  524.                 displayDirects_In();
  525.             }
  526.             else if(menu_option == 5){
  527.                 fireStaticQueries();
  528.             }
  529.             else if(menu_option == 6){
  530.                 fireDynamicQueries();
  531.             }
  532.             else if(menu_option == 7){
  533.                 insertPerson();
  534.             }
  535.             else if(menu_option == 8){
  536.                 insertMovies();
  537.             }
  538.             else if(menu_option == 9){
  539.                 insertActs_In();
  540.             }
  541.             else if(menu_option == 10){
  542.                 insertDirects_In();
  543.             }
  544.             else{
  545.                 System.out.println("You have entered a wrong choice");
  546.             }
  547.             //Scanner in2 = new Scanner(System.in);
  548.             System.out.println("Do you wish to continue(yes/no)");
  549.             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  550.             cont = br.readLine();
  551.            
  552.         }while(cont.equals("yes"));
  553.         System.out.println("Exiting...");
  554.         System.out.println("--------------------------------------------------------------");
  555.         CleanUp();
  556.     }
  557.  
  558. }
Add Comment
Please, Sign In to add comment