if(searchTerm.contains(".com") && searchTerm.contains("@")) {
System.out.println("In email check");
psmt.setString(1, "EMAIL_ID");
psmt.setString(2, searchTerm);
}else if(numresult==true){
System.out.println("In number check");
psmt.setString(1, "MOBILE_NUMBER");
psmt.setString(2, searchTerm);
}else if(uresult==true | alphanumeic==true) {
System.out.println("In username check");
psmt.setString(1, "USER_NAME");
psmt.setString(2, searchTerm);
}
rs = psmt.executeQuery();
while(rs.next()) {
HomeVo vo = new HomeVo();
vo.setId(rs.getInt("ID"));
vo.setFirstName(rs.getString("FIRST_NAME"));
vo.setLastName(rs.getString("LAST_NAME"));
vo.setEmailId(rs.getString("EMAIL_ID"));
vo.setNumber(rs.getString("MOBILE_NUMBER"));
vo.setQualification(rs.getString("QUALIFICATION"));
vo.setState(rs.getString("STATE"));
vo.setGender(rs.getString("GENDER"));
vo.setUserName(rs.getString("USER_NAME"));
vo.setDob(rs.getString("DOB"));
return vo;
}
Here is my MySQL Query.
String FETCH_USER_BY_SEARCHTERM = "SELECT * FROM SignUpTable WHERE ? = ? ";
Based on the search term given by the user, this logic checks if it is a username, email or mobile number. And feeds that as the input parameter. The control goes to the particular correct if statement, but won't return any values.
This is my first question here. Sorry, if I haven't posted the details correctly.
CodePudding user response:
I think there is probably some problem with the statement. You should log the prepared statement before executing it:
System.out.println(psmt);
rs = psmt.executeQuery();
Then you should check the SQL in the MySQL console, if it returns any results. Alternatively you can check the query log. See here how to enable it.