Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.movie.movieproductiondb.service;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.Time;
- public class DbService extends DbConnection {
- public class all{
- //objects
- //getters and setters
- };
- public class Film{
- //objects
- private Integer id;
- private String nazwa;
- private Float cena;
- private Time dlugosc;
- private String opis;
- private int id_tworcy;
- private int id_kategorii;
- // getters
- public Integer idGetter(){return id;}
- public String nazwaGetter(){return nazwa;}
- public Float cenaGetter(){return cena;}
- public Time dlugoscGetter(){return dlugosc;}
- public String opisGetter(){return opis;}
- public Integer idTworcyGetter(){return id_tworcy;}
- public Integer idKategoriiGetter(){return id_kategorii;}
- //setters
- //autoomatyczna inkrementacja w bazie danych: public Integer idSetter(Integer id){if()return id;}
- public boolean nazwaSetter(String nazwa){
- if(!nazwa.isEmpty()){
- this.nazwa = nazwa;
- return true;
- }
- else return false;
- }
- public boolean cenaSetter(Float cena) {
- if(cena>=0){
- this.cena=cena;
- return true;
- }
- else return false;
- }
- /** public boolean dlugoscSetter(Time dlugosc){
- if(dlugosc.setTime();)
- }
- **/
- public boolean opisSetter(String opis){
- if(!opis.isEmpty()){
- this.opis = opis;
- return true;
- }
- else return false;
- }
- public boolean idTworcySetter(Integer id){
- if(id.equals(0) || id<0){
- return false;
- }
- else{
- this.id_tworcy=id;
- return true;
- }
- }
- public boolean idKategoriiSetter(Integer id){
- if(id.equals(0) || id<0){
- return false;
- }
- else{
- this.id_kategorii=id;
- return true;
- }
- };
- public class FV{
- //objects
- // getters and setters
- };
- public class firma {
- //objects
- // getters and setters
- };
- public class Utwor {
- //objects
- // getters and setters
- };
- public class tworca {
- //objects
- // getters and setters
- };
- public class kategorie{
- //objects
- // getters and setters
- };
- public boolean readDataBase() {
- try {
- statement=connect.createStatement();
- resultSet=statement.executeQuery("SELECT * FROM film");
- writeResultSet(resultSet);
- return true;
- }catch (Exception e) {
- System.out.println("Blad polaczenia z baza danych");
- return false;
- }
- }
- public boolean insertIntoDatabase(){
- try {
- ////INSERT//////////////////////////////////////
- preparedStatement = connect.prepareStatement("INSERT INTO film VALUES(default, ?, ?, ?, ?,?,?)");
- String plc_nazwa="abc"; //pobieranie nazwy
- float plc_price = 0; //pobieranie kwoty
- int plc_H = 0; //pobieranie godziny
- int plc_M =0; //pobieranie minuty
- int plc_S = 0; //pobieranie sekundy
- String plc_desc ="abc"; //pobieranie opisu
- int plc_idtworcy = 0; //pobieranie tworcy
- int plc_idkategorii = 0; //pobieranie kategorii
- Time time = new Time(plc_H, plc_M,plc_S); //ustawienie zmiennej czasu
- preparedStatement.setString(1, plc_nazwa);
- preparedStatement.setFloat(2, plc_price);
- preparedStatement.setTime(3, time);
- preparedStatement.setString(4, plc_desc);
- preparedStatement.setInt(5,plc_idtworcy);
- preparedStatement.setInt(6,plc_idkategorii);
- preparedStatement.executeUpdate();
- return true;
- }catch (Exception e) {
- System.out.println("Blad polaczenia z baza danych");
- return false;
- }
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement