Facebook
From Luk, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 82
  1. private static void selectRecord(){
  2.       System.out.println("Inserisci i capi da visualizzare separati da,(*per visualizzarli tutti):");
  3.      
  4.     Scanner scanner=new Scanner(System.in);
  5.     String str=scanner.nextLine();
  6.     System.out.println("Inserisci le condizioni nel where:");
  7.       String condizione=scanner.nextLine();
  8.       String sql;
  9.       if(condizione.isEmpty() ) {
  10.         sql="SELECT"+str+"FROM Cast";
  11.       }else {
  12.         sql="SELECT"+str+"FROM Cast WHERE"+condizione;
  13.       }
  14.      
  15.       }
  16.     private static void insertRecord()throws SQLException {
  17.   System.out.println("Inserisci il codice Cast");
  18.   Scanner input;
  19.   String Id_cast=input.nextLine();
  20.   System.out.println("Inserisci il nome");
  21.   String Nome=input.nextLine();
  22.   System.out.println("Inserisci Cognome");
  23.   String Cognome=input.nextLine();
  24.   System.out.println("Inserisci il ruolo");
  25.   String Ruolo=input.nextLine();
  26.   String sql=  "INSERT INTO Cast VALUES('"+Id_cast+"','"+Nome+"','"+Cognome+"','"+Ruolo+"')";
  27.   Statement stmt=null;
  28.   try {
  29.     Connection conn;
  30.     stmt=conn.createStatement();
  31.     stmt.executeUpdate(sql);
  32.   }   catch(Exception e) {
  33.     System.out.println(e.getMessage());
  34.   }finally {
  35.     try {
  36.       if(stmt!=null) stmt.close();
  37.     } catch (Exception e1) {
  38.       System.out.println(e1.getMessage());
  39.     }
  40.   }
  41. }
  42.     private static void updateRecord()throws SQLException {
  43.       System.out.println("Inserisci il nuovo codice Cast");
  44.       Scanner input;
  45.     String Id_cast=input.nextLine();
  46.       System.out.println("Inserisci il nuovo nome");
  47.       String Nome=input.nextLine();
  48.       System.out.println("Inserisci il nuovo Cognome");
  49.       String Cognome=input.nextLine();
  50.       System.out.println("Inserisci il nuovo ruolo");
  51.       String Ruolo=input.nextLine();
  52.         String sql="UPDATE Cast SET Id_cast='"+Id_cast+"',Nome='"+Nome+"',Cognome='"+Cognome+"',Ruolo='"+Ruolo+"'";
  53.         Statement stmt=null;
  54.         try {
  55.           Connection conn;
  56.       stmt=conn.createStatement();
  57.         stmt.executeUpdate(sql);
  58.       }   catch(Exception e) {
  59.         System.out.println(e.getMessage());
  60.       }finally {
  61.         try {
  62.           if(stmt!=null) stmt.close();
  63.         } catch (Exception e1) {
  64.           System.out.println(e1.getMessage());
  65.         }
  66.     }
  67. }
  68.     private static void deleteRecord() {
  69.       System.out.println("Inserisci il codice Cast");
  70.     Scanner sc;
  71.     String Id_Cast=sc.nextLine();
  72.       String sql="DELETE FROM Cast WHERE Id_cast='"+Id_Cast+"'";
  73.       Statement stmt=null;
  74.     try {
  75.       Connection conn;
  76.       stmt=conn.createStatement();
  77.         stmt.executeUpdate(sql);
  78.       }   catch(Exception e) {
  79.         System.out.println(e.getMessage());
  80.       }finally {
  81.         try {
  82.           if(stmt!=null) stmt.close();
  83.         } catch (Exception e1) {
  84.           System.out.println(e1.getMessage());
  85.        
  86.       }
  87.     }
  88.  }