我写了一个含有两个条件的查询方法,代码如下:
但是三个条件的我就想不明白了,不知道该怎么写了.麻烦帮我看一下,谢谢!!!
request.setCharacterEncoding( "GBK "); //处理中文字符串
//构造查询SQL语句
String sqlString=null; //SQL语句
String name = request.getParameter( "name ");
String sex = request.getParameter( "sex ");
if(name==null||name.trim().length()==0)
sqlString = new String( "select * from abc ");
else
sqlString = new String( "select * from abc where name like '% "+name+ "% ' ");
if(sex==null||sex.trim().length()==0)
; //SQL语句不变
else
if(sqlString.indexOf( "where ")==-1) //SQL语句中没有where子句
sqlString = sqlString+ " where sex like ' "+sex+ " ' "+ " order by dd ";
else
sqlString = sqlString+ " and sex like ' "+sex+ " ' "+ " order by dd ";
%>