MySql教程

动态多条件mysql模糊查询

本文主要是介绍动态多条件mysql模糊查询,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

sql拼接函数:

 1     public static String Instructor_sql_whole_study(String[] val_ids,String[] val_values)
 2     {
 3         String sql="SELECT * from student_1_score where";
 4         for(int i=0;i<val_ids.length;i++)
 5         {
 6             sql+=Instructor_sql_study(sql,val_ids[i])+" like '%"+val_values[i]+"%'";
 7         }
 8         return sql;
 9     }
10     public static String Instructor_sql_study(String sql,String id)
11     {
12         String str="";
13         String and_str=" and ";
14         if(sh.getExpString("where$",sql).size()>0)
15         {
16             and_str=" ";
17         }
18         switch (id)
19         {
20             case "1":
21                 str=and_str+"name_student";break;
22             case "2":
23                 str=and_str+"name_course";break;
24             case "3":
25                 str=and_str+"credit";break;
26             case "4":
27                 str=and_str+"term";break;
28             case "5":
29                 str=and_str+"class";break;
30         }
31         return str;
32     }

 

这篇关于动态多条件mysql模糊查询的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!