Commit d5a7782f authored by Daniel Kim's avatar Daniel Kim
Browse files

fix

parent 5d318548
......@@ -11,6 +11,8 @@ public class ClientApplication {
static Connection c;
static String User;
static SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
static HashMap<String, String> columnMapper = new HashMap<String, String>();
public static void main(String[] args) {
boolean exitLoop = false;
if (authDatabase()) {
......@@ -18,6 +20,34 @@ public class ClientApplication {
} else {
exitLoop = true;
}
columnMapper.put("title", "Title");
columnMapper.put("originalTitle", "Original Title");
columnMapper.put("genre", "Genre(s)");
columnMapper.put("year", "Year");
columnMapper.put("releaseDate", "Release Date");
columnMapper.put("duration", "Duration (minutes)");
columnMapper.put("description", "Description");
columnMapper.put("averageRating", "Average Rating");
columnMapper.put("totalRating", "Total Ratings");
columnMapper.put("metascore", "Metascore");
columnMapper.put("incomeDomestic", "Domestic Income");
columnMapper.put("incomeWorldwide", "Worldwide Income");
columnMapper.put("budget", "Budget");
columnMapper.put("productionCompany", "Production Company(ies)");
columnMapper.put("language", "Language(s)");
columnMapper.put("userID", "User ID");
columnMapper.put("comment", "Comment");
columnMapper.put("name", "Name");
columnMapper.put("birthName", "Birth Name");
columnMapper.put("height", "Height");
columnMapper.put("bio", "Biography");
columnMapper.put("birthDetails", "Birth Details");
columnMapper.put("dateOfBirth", "Date of Birth");
columnMapper.put("dateOfDeath", "Date of Death");
columnMapper.put("placeOfDeath", "Place of Death");
columnMapper.put("reasonOfDeath", "Reason of Death");
String command = "";
while (!exitLoop) {
System.out.println("Type \"se <movie/genre/person> <keywords>\" to search movies by title, genre, or person. Type \"hp\" to see other commands. Type \"qt\" to quit.");
......@@ -174,7 +204,9 @@ public class ClientApplication {
for (int i = 1; i <= columnsNumber; i++) {
if (attributes.contains(rsmd.getColumnName(i))) {
matchingColumns.add(i);
System.out.print(rsmd.getColumnName(i) + ", ");
if (columnMapper.containsKey(rsmd.getColumnName(i))) {
System.out.print(columnMapper.get(rsmd.getColumnName(i)) + ", ");
}
}
}
System.out.println();
......@@ -204,7 +236,9 @@ public class ClientApplication {
setItem++;
if (setItem == row) {
for (int i = 1; i <= columnsNumber; i++) {
System.out.print(rsmd.getColumnName(i) + ": ");
if (columnMapper.containsKey(rsmd.getColumnName(i))) {
System.out.print(columnMapper.get(rsmd.getColumnName(i)) + ": ");
}
String columnValue = rs.getString(i);
System.out.print(columnValue);
System.out.println();
......@@ -231,7 +265,7 @@ public class ClientApplication {
String searchMovieQueryString = "select "
+ "title, "
+ "originalTitle, "
+ "group_concat(genre separator ', ') AS Genre, "
+ "group_concat(genre separator ', ') AS genre, "
+ "year, "
+ "releaseDate, "
+ "duration, "
......@@ -312,11 +346,15 @@ public class ClientApplication {
boolean exitLoop2 = false;
System.out.println();
System.out.println("Found " + numResults + " result(s). To show advanced details for a movie, type the corresponding item number.");
System.out.println("Type \'0\' to exit.");
while (!exitLoop2) {
String command = input.nextLine();
if (Integer.parseInt(command) < 1 || Integer.parseInt(command) > numResults) {
if (Integer.parseInt(command) < 0 || Integer.parseInt(command) > numResults) {
System.out.println("Index out of range.");
}
else if (Integer.parseInt(command) == 0) {
exitLoop2 = true;
}
else {
rs.beforeFirst();
printQueryResults(rs, Integer.parseInt(command));
......@@ -374,11 +412,15 @@ public class ClientApplication {
exitLoop2 = false;
System.out.println();
System.out.println("Found " + numResults + " result(s). To show advanced details for a movie, type the corresponding item number.");
System.out.println("Type \'0\' to exit.");
while (!exitLoop2) {
String command = input.nextLine();
if (Integer.parseInt(command) < 1 || Integer.parseInt(command) > numResults) {
if (Integer.parseInt(command) < 0 || Integer.parseInt(command) > numResults) {
System.out.println("Index out of range.");
}
else if (Integer.parseInt(command) == 0) {
exitLoop2 = true;
}
else {
rs.beforeFirst();
int setItem = 0;
......@@ -438,11 +480,15 @@ public class ClientApplication {
exitLoop2 = false;
System.out.println();
System.out.println("Found " + numResults + " result(s). To show advanced details for a person, type the corresponding item number.");
System.out.println("Type \'0\' to exit.");
while (!exitLoop2) {
String command = input.nextLine();
if (Integer.parseInt(command) < 1 || Integer.parseInt(command) > numResults) {
if (Integer.parseInt(command) < 0 || Integer.parseInt(command) > numResults) {
System.out.println("Index out of range.");
}
else if (Integer.parseInt(command) == 0) {
exitLoop2 = true;
}
else {
rs.beforeFirst();
int setItem = 0;
......@@ -728,8 +774,8 @@ public class ClientApplication {
String server, pwd, db;
// System.out.print("Enter the SQL server to connect to: ");
// server = input.nextLine();
// server = "127.0.0.1:3306";
server = "marmoset03.shoshin.uwaterloo.ca";
server = "127.0.0.1:3306";
// server = "marmoset03.shoshin.uwaterloo.ca";
System.out.print("Enter username for the SQL server: ");
User = input.nextLine();
pwd = new String(System.console().readPassword("Enter password for the SQL server: "));
......@@ -773,6 +819,7 @@ public class ClientApplication {
System.out.println("Use the following form to add a movie entry");
System.out.println("Type the number at the beginning of the line to edit the property.");
System.out.println("Required fields are marked with a '*'.");
System.out.println("Type \'c\' to confirm changes. Type \'x\' to cancel.");
System.out.println("1: Title *");
System.out.println("2: Description");
System.out.println("3: Release date");
......@@ -927,6 +974,12 @@ public class ClientApplication {
System.out.println(String.format("Movie successfully added (tt%s).", maxId));
break;
case "x":
exitLoop = true;
break;
default:
System.out.println("Invalid command " + command);
break;
}
}
} catch (Exception e) {
......@@ -977,6 +1030,7 @@ public class ClientApplication {
while (!exitLoop) {
System.out.println("Use the following form to edit a movie entry");
System.out.println("Type the number at the beginning of the line to edit the property.");
System.out.println("Type \'c\' to confirm your changes. Type \'x\' to cancel.");
System.out.println("1: Title");
System.out.println("2: Description");
System.out.println("3: Release date");
......@@ -1120,6 +1174,12 @@ public class ClientApplication {
System.out.println(String.format("Movie successfully edited (%s).", movieID));
break;
case "x":
exitLoop = true;
break;
default:
System.out.println("Invalid command " + command);
break;
}
}
} catch (Exception e) {
......@@ -1175,6 +1235,7 @@ public class ClientApplication {
System.out.println("Use the following form to add a person entry.");
System.out.println("Type the number at the beginning of the line to edit the property.");
System.out.println("Required fields are marked with a '*'.");
System.out.println("Type \'c\' to confirm your changes. Type \'x\' to cancel.");
System.out.println("1: Name *");
System.out.println("2: Birth Name");
System.out.println("3: Height");
......@@ -1275,6 +1336,9 @@ public class ClientApplication {
System.out.println(e);
}
break;
case "x":
exitLoop = true;
break;
default:
System.out.println("Invalid command " + command);
break;
......@@ -1313,8 +1377,9 @@ public class ClientApplication {
boolean exitLoop = false;
String command = "";
while (!exitLoop) {
System.out.println("Type the number at the beginning of the line to edit the property. Type 'c' to confirm your changes. Type 'x' to cancel.");
System.out.println("Type the number at the beginning of the line to edit the property.");
System.out.println("Required fields are marked with a '*'.");
System.out.println("Type \'c\' to confirm your changes. Type \'x\' to cancel.");
System.out.println("1: Name * - " + name);
System.out.println("2: Birth Name - " + birthName);
System.out.println("3: Height - " + height);
......@@ -1410,6 +1475,7 @@ public class ClientApplication {
exitLoop = true;
break;
default:
System.out.println("Invalid command " + command);
break;
}
}
......@@ -1424,7 +1490,7 @@ public class ClientApplication {
public static void deletePerson(String q) {
try {
PreparedStatement query = c.prepareStatement("select personID, name from People where name like ?% limit 10");
PreparedStatement query = c.prepareStatement("select personID, name from People where name like ? limit 10");
query.setString(1, q);
ResultSet rs = query.executeQuery();
......
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