Commit 229b136a authored by RAYMOND XIA's avatar RAYMOND XIA
Browse files

refactored review search strings

parent d0b85ccd
......@@ -150,10 +150,10 @@ public class ClientApplication {
}
public static void addReview(String entity) {
String searchMovieQueryPrefix = "select * from Movies where title like ";
String searchMovieQueryString = "select * from Movies where title like '%s%%'";
try {
Statement st = c.createStatement();
String query = searchMovieQueryPrefix + "'" + entity + "%'";
String query = String.format(searchMovieQueryString, entity);
ResultSet rs = st.executeQuery(query);
if (rs.next()) {
......@@ -162,7 +162,7 @@ public class ClientApplication {
query = String.format("select * from Reviews where movieID = '%s' and userID = '%s'", movieID, User);
rs = st.executeQuery(query);
if (rs.next()) {
System.out.println("You have already added a review for this movie.");
System.out.println("You have already added a review for " + movieTitle + ".");
} else {
// Give user option to add review to movie
......@@ -185,10 +185,10 @@ public class ClientApplication {
}
public static void editReview(String entity) {
String searchMovieQueryPrefix = "select * from Movies where title like ";
String searchMovieQueryString = "select * from Movies where title like '%s%%'";
try {
Statement st = c.createStatement();
String query = searchMovieQueryPrefix + "'" + entity + "%'";
String query = String.format(searchMovieQueryString, entity);
ResultSet rs = st.executeQuery(query);
if (rs.next()) {
......@@ -219,20 +219,22 @@ public class ClientApplication {
}
public static void deleteReview(String entity) {
String searchMovieQueryPrefix = "select * from Movies where title like ";
String searchMovieQueryString = "select * from Movies where title like '%s%%'";
try {
Statement st = c.createStatement();
String query = searchMovieQueryPrefix + "'" + entity + "%'";
String query = String.format(searchMovieQueryString, entity);
ResultSet rs = st.executeQuery(query);
if (rs.next()) {
System.out.println("Are you sure you want to delete this review? Type y to confirm. Type any other character to cancel.");
String movieID = rs.getString(1);
String movieTitle = rs.getString(2);
System.out.println("Are you sure you want to delete your review for " + movieTitle + "?");
System.out.println("Type y to confirm. Type any other character to cancel.");
String command = "";
command = input.nextLine();
if (command.equals("y")) {
String movieID = rs.getString(1);
query = String.format("select * from Reviews where movieID = '%s' and userID = '%s'", movieID, User);
rs = st.executeQuery(query);
if (!rs.next()) {
......
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