Reputation: 83
I am new to MySQL and don't really know how to check if in the column "friendCode" the same value already exist and if that's the case it should look if in the same row in the "watched" column the value "0" is. I have already managed to check whether the code exists in a row. I just don't know how to look for the second condition.
Here is a picture how the table looks like:
And here that what I already managed to do:
public static boolean checkRow(String query) {
boolean ret = false;
try (Connection con = DriverManager.getConnection(url, user, password)) {
Statement stmt = con.createStatement();
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
if (rs.next() && !rs.getString("watched").equals(0)) {
ret = false;
} else {
ret = true;
}
rs.close();
stmt.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return ret;
}
Upvotes: 0
Views: 93
Reputation: 34
I think you are not written any select query in this program. If you are calling from the main method just check and try the below steps.
In Given Table watched column have integer DataType data.
Your Compare to String type.
Try it my code it's working if you have any concern revert back to this comment.
public static boolean checkRow(String query) {
boolean ret = false;
try (Connection con = DriverManager.getConnection(url, user, password)) {
Statement stmt = con.createStatement();
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
if (rs.next() && rs.getString("watched")!=0) {
ret = false;
} else {
ret = true;
}
rs.close();
stmt.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return ret;
}
Upvotes: 1