I am trying to check if an entry exists within my table. I have used the following resources and run the code in mysql workbench to see if i was running something wrong but that wasn't the case.
Check if ResultSet is filled -> Is ResultSet Filled
SQL Syntax -> SQL
This is the current code i'm running
public static Boolean exists(Table t, int userId){
boolean e = false;
if (connection != null){
try {
String SQL = "SELECT EXISTS(SELECT 1 FROM " + t.table + " WHERE id = " + String.valueOf(userId) + ")";
System.out.println(SQL);
stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(SQL);
if (isFilled(rs))
e = true;
} catch (SQLException l) {
l.printStackTrace();
}
}
return e;
}
public static boolean isFilled(ResultSet rs){
boolean isEmpty = true;
try {
while(rs.next()){
isEmpty = false;
}
} catch (SQLException e) {
e.printStackTrace();
}
return !isEmpty;
}
The problem is exists always returns true no matter the userID I enter