|
@@ -25,7 +25,6 @@ public class DataBaseConnector {
|
|
|
|
|
|
} catch (SQLException ex) {
|
|
|
//exception
|
|
|
-
|
|
|
ex.printStackTrace();
|
|
|
}
|
|
|
}
|
|
@@ -101,5 +100,73 @@ public class DataBaseConnector {
|
|
|
return resultedMovies;
|
|
|
}
|
|
|
|
|
|
+ public void addMovie(Movie movie) {
|
|
|
+ try {
|
|
|
+ Statement statement = conn.createStatement();
|
|
|
+ String req;
|
|
|
+
|
|
|
+ String commandString;
|
|
|
+ String intoPart = "";
|
|
|
+ String valPart = "";
|
|
|
+
|
|
|
+ if (!movie.name().equals("Movie_name_undefined")) {
|
|
|
+ intoPart += " name,";
|
|
|
+ valPart += " '" + movie.name() + "',";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!movie.genre().equals("Movie_genre_undefined")) {
|
|
|
+ intoPart += " genre,";
|
|
|
+ valPart += " '" + movie.genre() + "',";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!movie.description().equals("Movie_description_undefined")) {
|
|
|
+ intoPart += " description,";
|
|
|
+ valPart += " '" + movie.description() + "',";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!movie.duration().equals("Movie_duration_undefined")) {
|
|
|
+ intoPart += " duration,";
|
|
|
+ valPart += " '" + movie.duration() + "',";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!movie.rating().equals("Movie_rating_undefined")) {
|
|
|
+ intoPart += " user_rating,";
|
|
|
+ valPart += " '" + movie.rating() + "',";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!movie.year().equals("Movie_year_undefined")) {
|
|
|
+ intoPart += " year,";
|
|
|
+ valPart += " '" + movie.year() + "',";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!movie.studio().equals("Movie_studio_undefined")) {
|
|
|
+ intoPart += " studio,";
|
|
|
+ valPart += " '" + movie.studio() + "',";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!movie.director().equals("Movie_director_undefined")) {
|
|
|
+ intoPart += " director,";
|
|
|
+ valPart += " '" + movie.director() + "',";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!movie.getImageLink().equals("Movie_ImageLink_undefined")) {
|
|
|
+ intoPart += " image_link,";
|
|
|
+ valPart += " '" + movie.getImageLink() + "',";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (intoPart.charAt(intoPart.length() - 1) == ',')
|
|
|
+ intoPart = intoPart.substring(0, intoPart.length() - 1);
|
|
|
+ if (valPart.charAt(valPart.length() - 1) == ',')
|
|
|
+ valPart = valPart.substring(0, valPart.length() - 1);
|
|
|
|
|
|
+ //сборка текста запроса
|
|
|
+ req = "INSERT INTO Movies (" + intoPart + ") ";
|
|
|
+ req += "values (" + valPart + ");";
|
|
|
+
|
|
|
+ //выполнение запроса
|
|
|
+ statement.execute(req);
|
|
|
+ } catch (SQLException ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|