I have my set Appointments Frame for doctors and inside it have Patient Records and of course the doctor and then i have a search field so whenever i'm finding some doctors i will just have to search their name, there's is no error but the problem is whenever the search field is empty the jtable is filled all of the User including the admin Nurse recep etc.
and this is my code
try{
String like = DoctorSearch.getText();
String sql = "Select ID,First_Name,[M.I],Last_Name from User_Table\n" +
"where Role_ID = 3 AND Last_Name LIKE '"+like+"%' or First_Name LIKE '"+like+"%'";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
DoctorNames.setModel(DbUtils.resultSetToTableModel(rs));
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}finally {
try {
rs.close();
pst.close();
}catch(Exception e){
}
}
But when i remove the
First_Name LIKE '"+like+"%'
it is doing right what can i do to make it right?