0

enter image description here

I have many case to search database, so i don't want repeat if/else statement, is there an other good solution ? nom and dd and ddd are input name,

Sorry for my bad english!

Cù Đức Hiếu
  • 5,569
  • 4
  • 27
  • 35

1 Answers1

0
String requete = "Select * from employees where 1=1 ";
if (!nom.isEmpty()) {
    requete += " and last_name like '"+nom+"%'";
}
if (!dd.isEmpty() && !ddd.isEmpty()) {
    requete  += " and hire_date between '"+dd+"' and '"+ddd+"';
}

This way you can optimiz, so you can get rid of the same if condition in the else block.

Senthil
  • 2,156
  • 1
  • 14
  • 19