Advertisement
RynkunPokemon

new

Feb 4th, 2022
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.31 KB | None | 0 0
  1. package com.movie.movieproductiondb.service;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.Time;
  5.  
  6.  
  7.  
  8. public class DbService extends DbConnection {
  9.  
  10.     public class all{
  11.         //objects
  12.  
  13.  
  14.  
  15.  
  16.         //getters and setters
  17.  
  18.  
  19.     };
  20.  
  21.     public class Film{
  22.         //objects
  23.     private Integer id;
  24.     private String nazwa;
  25.     private Float cena;
  26.     private Time dlugosc;
  27.     private String opis;
  28.     private int id_tworcy;
  29.     private int id_kategorii;
  30.  
  31.  
  32.         // getters
  33.         public Integer idGetter(){return id;}
  34.         public String nazwaGetter(){return nazwa;}
  35.         public Float cenaGetter(){return cena;}
  36.         public Time dlugoscGetter(){return dlugosc;}
  37.         public String opisGetter(){return opis;}
  38.         public Integer idTworcyGetter(){return id_tworcy;}
  39.         public Integer idKategoriiGetter(){return id_kategorii;}
  40.  
  41.         //setters
  42.  
  43.        //autoomatyczna inkrementacja w bazie danych:  public Integer idSetter(Integer id){if()return id;}
  44.         public boolean nazwaSetter(String nazwa){
  45.             if(!nazwa.isEmpty()){
  46.                 this.nazwa = nazwa;
  47.                 return true;
  48.             }
  49.             else return false;
  50.         }
  51.         public boolean cenaSetter(Float cena) {
  52.             if(cena>=0){
  53.                 this.cena=cena;
  54.                 return true;
  55.             }
  56.             else return false;
  57.         }
  58.        /** public boolean dlugoscSetter(Time dlugosc){
  59.             if(dlugosc.setTime();)
  60.         }
  61.         **/
  62.         public boolean opisSetter(String opis){
  63.             if(!opis.isEmpty()){
  64.                 this.opis = opis;
  65.                 return true;
  66.             }
  67.             else return false;
  68.         }
  69.         public boolean idTworcySetter(Integer id){
  70.             if(id.equals(0) || id<0){
  71.                 return false;
  72.             }
  73.             else{
  74.                 this.id_tworcy=id;
  75.                 return true;
  76.             }
  77.         }
  78.         public boolean idKategoriiSetter(Integer id){
  79.             if(id.equals(0) || id<0){
  80.                 return false;
  81.             }
  82.             else{
  83.                 this.id_kategorii=id;
  84.                 return true;
  85.             }
  86.     };
  87.     public class FV{
  88.         //objects
  89.  
  90.  
  91.  
  92.         // getters and setters
  93.  
  94.     };
  95.     public class firma {
  96.         //objects
  97.  
  98.  
  99.  
  100.         // getters and setters
  101.     };
  102.     public class Utwor {
  103.         //objects
  104.  
  105.  
  106.  
  107.         // getters and setters
  108.     };
  109.     public class tworca {
  110.         //objects
  111.  
  112.  
  113.  
  114.         // getters and setters
  115.     };
  116.     public class kategorie{
  117.         //objects
  118.  
  119.  
  120.  
  121.         // getters and setters
  122.     };
  123.  
  124.     public boolean readDataBase() {
  125.  
  126.         try {
  127.             statement=connect.createStatement();
  128.             resultSet=statement.executeQuery("SELECT * FROM film");
  129.             writeResultSet(resultSet);
  130.             return true;
  131.         }catch (Exception e) {
  132.             System.out.println("Blad polaczenia z baza danych");
  133.             return false;
  134.         }
  135.     }
  136.  
  137.     public boolean insertIntoDatabase(){
  138.         try {
  139.             ////INSERT//////////////////////////////////////
  140.             preparedStatement = connect.prepareStatement("INSERT INTO film VALUES(default, ?, ?, ?, ?,?,?)");
  141.             String plc_nazwa="abc"; //pobieranie nazwy
  142.             float plc_price = 0; //pobieranie kwoty
  143.             int plc_H = 0; //pobieranie godziny
  144.             int plc_M =0; //pobieranie minuty
  145.             int plc_S = 0; //pobieranie sekundy
  146.             String plc_desc ="abc"; //pobieranie opisu
  147.             int plc_idtworcy = 0; //pobieranie tworcy
  148.             int plc_idkategorii = 0; //pobieranie kategorii
  149.             Time time = new Time(plc_H, plc_M,plc_S); //ustawienie zmiennej czasu
  150.             preparedStatement.setString(1, plc_nazwa);
  151.             preparedStatement.setFloat(2, plc_price);
  152.             preparedStatement.setTime(3, time);
  153.             preparedStatement.setString(4, plc_desc);
  154.             preparedStatement.setInt(5,plc_idtworcy);
  155.             preparedStatement.setInt(6,plc_idkategorii);
  156.             preparedStatement.executeUpdate();
  157.             return true;
  158.         }catch (Exception e) {
  159.             System.out.println("Blad polaczenia z baza danych");
  160.             return false;
  161.         }
  162.     }
  163.  
  164.  
  165.  
  166. }}
  167.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement