-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovieDatabaseManager.java
More file actions
74 lines (58 loc) · 2.22 KB
/
MovieDatabaseManager.java
File metadata and controls
74 lines (58 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.sql.*;
import java.util.ArrayList;
// can be deleted ???
public class MovieDatabaseManager {
private myJDBC jdbc;
public MovieDatabaseManager(myJDBC jdbc) {
this.jdbc = jdbc;
}
public ArrayList<Movie> fetchMovies(int locationID) {
String query = null;
ArrayList<Movie> movies = new ArrayList<>();
PreparedStatement statement = null;
try {
if (locationID == -1){
query = "SELECT * FROM MOVIE";
statement = jdbc.dbConnect.prepareStatement(query);
} else{
query = "SELECT * FROM MOVIE WHERE MovieID IN (" +
"SELECT MovieID FROM SHOWTIME WHERE TheatreID = ?)";
statement = jdbc.dbConnect.prepareStatement(query);
statement.setInt(1, locationID);
}
ResultSet results = statement.executeQuery();
while (results.next()) {
int movieID = results.getInt("MovieID");
String title = results.getString("Title");
String genre = results.getString("Genre");
Movie movie = new Movie(movieID, title, genre);
movies.add(movie);
}
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
return movies;
}
public ArrayList<Movie> fetchMovies(String search ) {
ResultSet results;
ArrayList<Movie> movies = new ArrayList<>();
try {
Statement myStmt = jdbc.dbConnect.createStatement();
results = myStmt.executeQuery("select M.MovieID, M.Title\n" +
"from MOVIE as M\n" +
"where LOCATE(LOWER('" + search + "'), LOWER(M.Title)) > 0;");
while (results.next()) {
int movieID = results.getInt("MovieID");
String title = results.getString("Title");
String genre = results.getString("Genre");
Movie movie = new Movie(movieID, title, genre);
movies.add(movie);
}
myStmt.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
return movies;
}
}