动态多条件mysql模糊查询
sql拼接函数
public static String Instructor_sql_whole_study(String[] val_ids,String[] val_values)
{
String sql="SELECT * from student_1_score where";
for(int i=0;i<val_ids.length;i++)
{
sql+=Instructor_sql_study(sql,val_ids[i])+" like '%"+val_values[i]+"%'";
}
return sql;
}
public static String Instructor_sql_study(String sql,String id)
{
String str="";
String and_str=" and ";
if(sh.getExpString("where$",sql).size()>0)
{
and_str=" ";
}
switch (id)
{
case "1":
str=and_str+"name_student";break;
case "2":
str=and_str+"name_course";break;
case "3":
str=and_str+"credit";break;
case "4":
str=and_str+"term";break;
case "5":
str=and_str+"class";break;
}
return str;
}