|
@@ -0,0 +1,69 @@
|
|
|
+package com.moviesdb;
|
|
|
+
|
|
|
+import java.sql.*;
|
|
|
+import com.moviesdb.Movie;
|
|
|
+import java.util.Properties;
|
|
|
+
|
|
|
+public class DataBaseConnector {
|
|
|
+
|
|
|
+ Connection conn = null;
|
|
|
+ public String result = "bad";
|
|
|
+
|
|
|
+ public void initConnection(String ui_user, String ui_pass) {
|
|
|
+ try {
|
|
|
+ // connect way #2
|
|
|
+ String url = "jdbc:mysql://192.168.192.1/moviesdb";
|
|
|
+ String user = ui_user;
|
|
|
+ String password = ui_pass;
|
|
|
+ user = "Veloe";
|
|
|
+ password = "Password1*";
|
|
|
+
|
|
|
+ conn = DriverManager.getConnection(url, user, password);
|
|
|
+ if (conn != null) {
|
|
|
+ result = "good";
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (SQLException ex) {
|
|
|
+ //exception
|
|
|
+
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Movie getMovieInfo(int movieId) {
|
|
|
+ Movie resultedMovie = new Movie();
|
|
|
+
|
|
|
+ try {
|
|
|
+ Statement statement = conn.createStatement();
|
|
|
+ String req = "SELECT * FROM Movies WHERE id = " + movieId + ";";
|
|
|
+ ResultSet rs = statement.executeQuery(req);
|
|
|
+
|
|
|
+ while(rs.next()){
|
|
|
+ resultedMovie.setId(movieId);
|
|
|
+ resultedMovie.setName(rs.getString("name"));
|
|
|
+ resultedMovie.setGenre(rs.getString("genre"));
|
|
|
+ resultedMovie.setDescription(rs.getString("description"));
|
|
|
+ resultedMovie.setDuration(rs.getString("duration"));
|
|
|
+ resultedMovie.setRating(rs.getString("user_rating"));
|
|
|
+ resultedMovie.setYear(rs.getString("year"));
|
|
|
+ resultedMovie.setStudio(rs.getString("studio"));
|
|
|
+ resultedMovie.setDirector(rs.getString("director"));
|
|
|
+ resultedMovie.setCover(rs.getString("image_link"));
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (SQLException ex) {
|
|
|
+ //exception
|
|
|
+
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ;
|
|
|
+
|
|
|
+
|
|
|
+ return resultedMovie;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|