Commit 1e5bba57 authored by kcchik's avatar kcchik
Browse files

lmao

parent 3b6606f4
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Scanner;
import java.sql.*;
import java.text.SimpleDateFormat;
......@@ -329,6 +330,10 @@ public class ClientApplication {
public static void addMovie() {
// User fills in everything and confirms values
ArrayList<String> genres = new ArrayList<>();
ArrayList<String> languages = new ArrayList<>();
ArrayList<String> countries = new ArrayList<>();
HashMap<String, String> people = new HashMap<String, String>();
HashMap<String, String> values = new HashMap<String, String>();
String command = "";
boolean exitLoop = false;
......@@ -372,7 +377,7 @@ public class ClientApplication {
case "4":
System.out.println("Search for a genre");
try {
values.put("genre", searchCriteria("Genres", "genre"));
genres.add(searchCriteria("Genres", "genre"));
} catch (Exception e) {
System.out.println(e);
}
......@@ -394,13 +399,13 @@ public class ClientApplication {
i++;
}
command = input.nextLine().trim();
values.put("person", results[Integer.parseInt(command) - 1]);
System.out.println("Enter their role");
String role = input.nextLine().trim();
people.put(results[Integer.parseInt(command) - 1], role);
} catch (Exception e) {
System.out.println(e);
}
System.out.println("Enter their role");
command = input.nextLine().trim();
values.put("role", command);
break;
case "6":
System.out.println("Enter a duration (min)");
......@@ -410,7 +415,7 @@ public class ClientApplication {
case "7":
System.out.println("Search for a language");
try {
values.put("language", searchCriteria("Languages", "language"));
languages.add(searchCriteria("Languages", "language"));
} catch (Exception e) {
System.out.println(e);
}
......@@ -418,7 +423,7 @@ public class ClientApplication {
case "8":
System.out.println("Search for a country");
try {
values.put("country", searchCriteria("Countries", "country"));
countries.add(searchCriteria("Countries", "country"));
} catch (Exception e) {
System.out.println(e);
}
......@@ -468,40 +473,43 @@ public class ClientApplication {
);
st.executeUpdate(query);
if (values.containsKey("genre")) {
if (!genres.isEmpty()) {
st = c.createStatement();
query = String.format("insert into GenresInMovies values ('%s', '%s')",
"tt" + maxId,
values.get("genre")
);
query = "insert into GenresInMovies (movieID, genre) values ('tt" + maxId + "','";
query += String.join("'),('tt" + maxId + "','", genres);
query += "');";
st.executeUpdate(query);
}
if (values.containsKey("language")) {
if (!languages.isEmpty()) {
st = c.createStatement();
query = String.format("insert into LanguagesInMovies values ('%s', '%s')",
"tt" + maxId,
values.get("language")
);
query = "insert into LanguagesInMovies (movieID, language) values ('tt" + maxId + "','";
query += String.join("'),('tt" + maxId + "','", languages);
query += "');";
st.executeUpdate(query);
}
if (values.containsKey("country")) {
if (!countries.isEmpty()) {
st = c.createStatement();
query = String.format("insert into CountriesInMovies values ('%s', '%s')",
"tt" + maxId,
values.get("country")
);
query = "insert into CountriesInMovies (movieID, country) values ('tt" + maxId + "','";
query += String.join("'),('tt" + maxId + "','", countries);
query += "');";
st.executeUpdate(query);
}
if (values.containsKey("person") && values.containsKey("role")) {
if (!people.isEmpty()) {
st = c.createStatement();
query = String.format("insert into PeopleInMovies values ('%s', '%s', '%s')",
"tt" + maxId,
values.get("person"),
values.get("role")
);
query = "insert into PeopleInMovies (movieID, personID, role) values ";
for (HashMap.Entry<String, String> entry : people.entrySet()) {
String personID = entry.getKey();
String role = entry.getValue();
query += String.format("('%s','%s','%s'),",
"tt" + maxId,
personID,
role
);
}
query = query.substring(0, query.length() - 1) + ";";
st.executeUpdate(query);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment