Guest User

Untitled

a guest
Mar 11th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/films?", connInfo);
  2. PreparedStatement statement = connection.prepareStatement("INSERT INTO films(name_film, rating, description, poster, path, year_of_release) VALUE (?, ?, ?, ?, ?, ?)")) {
  3.  
  4. for (File film:films) {
  5.  
  6. String actors = new String(Files.readAllBytes(Paths.get(film.getPath() + "/actors.txt")));
  7. String description = new String(Files.readAllBytes(Paths.get(film.getPath() + "/description.txt")));
  8. String genres = new String(Files.readAllBytes(Paths.get(film.getPath() + "/genres.txt")));
  9. String names = new String(Files.readAllBytes(Paths.get(film.getPath() + "/names.txt")));
  10. String Producer = new String(Files.readAllBytes(Paths.get(film.getPath() + "/Producer.txt")));
  11. String year = new String(Files.readAllBytes(Paths.get(film.getPath() + "/year.txt")));
  12.  
  13. String[] namesArray = names.split(" / ");
  14. for (int i = 0; i<namesArray.length; i++) {
  15. namesArray[i] = namesArray[i].trim();
  16. }
  17.  
  18.  
  19.  
  20. statement.setString(1, new Gson().toJson(namesArray));
  21. statement.setInt(2,5);
  22. statement.setString(3, description);
  23. statement.setString(4,film.getPath() + "/poster.jpg");
  24. statement.setString(5, film.getPath() + "filmName");
  25. statement.setInt(6,Integer.parseInt(year.trim()));
  26. statement.executeUpdate();
  27.  
  28.  
  29. }//for
  30. }
  31.  
  32. INSERT INTO films(name_film, rating, description, poster, path, year_of_release) VALUE ("world's dog", 5, "Привет мир", "Пока мир", "world's dog", 2017);
Add Comment
Please, Sign In to add comment