复合查询的sql问题! http://community.csdn.net/Expert/topic/3691/3691688.xml?temp=.9523126 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select * from 表名 where 1 = 1然后用一个循环把用户输入的条件(加and)连接起来。 public String makesql(String staffname,String sax,String idcardno,String bthdate,String nation,String nativeplace){ boolean ifand=false; String sql="select staffname,sax,idcardno,bthdate,nation,nativeplace"; sql+=" from bs_staffinfo where "; if (!staffname.equals("")){ sql+=" staffname='"+staffname+"' "; ifand=true; } if (!sax.equals("")){ if (ifand) sql+=" and "; sql+=" sax="+sax; ifand=true; } if (!idcardno.equals("")){ if (ifand) sql+=" and "; sql+=" idcardno ='"+ idcardno+"'"; ifand=true; }if (!bthdate.equals("")){ if (ifand) sql+=" and "; sql+=" bthdate ='"+ bthdate+"'"; ifand=true; }if (!nation.equals("")){ if (ifand) sql+=" and "; sql+=" nation ='"+ nation+"'"; ifand=true; }if (!nativeplace.equals("")){ if (ifand) sql+=" and "; sql+=" nativeplace ='"+ nativeplace+"'"; ifand=true; } return sql; }我最近刚写的一个例子,这个是一个方法在前面还经过判断,如果是NULL的就转换成“”;<%!public String handleNullVal(String str2handle){ if (str2handle==null) return ""; else return str2handle;}我实现了效果,希望你能看懂 求高手们给推荐一两本java方面的书籍 JAVA如何把代码封装成像sdk那样的类?或者在哪里有封装好的工具类 求指教。。。关于Java GUI的布局问题(急) java 面试题 高手帮忙解决下坦克大战联网游戏的问题 怎样让包含JTable的JScrollPane占据整个JPanel 如何在类级别抛出异常?(throws的用法) java在递归的时候,可以返回一个集合如ArrayList吗? java中,如何判断socket连接的状态,如何判断是否已断线? 菜鸟问题 急救:谁有JAVA的时间选择器控件 请问,何谓bean?
boolean ifand=false; String sql="select staffname,sax,idcardno,bthdate,nation,nativeplace";
sql+=" from bs_staffinfo where "; if (!staffname.equals("")){
sql+=" staffname='"+staffname+"' ";
ifand=true;
}
if (!sax.equals("")){
if (ifand) sql+=" and ";
sql+=" sax="+sax;
ifand=true;
}
if (!idcardno.equals("")){
if (ifand) sql+=" and ";
sql+=" idcardno ='"+ idcardno+"'";
ifand=true;
}if (!bthdate.equals("")){
if (ifand) sql+=" and ";
sql+=" bthdate ='"+ bthdate+"'";
ifand=true;
}if (!nation.equals("")){
if (ifand) sql+=" and ";
sql+=" nation ='"+ nation+"'";
ifand=true;
}if (!nativeplace.equals("")){
if (ifand) sql+=" and ";
sql+=" nativeplace ='"+ nativeplace+"'";
ifand=true;
}
return sql;
}我最近刚写的一个例子,这个是一个方法在前面还经过判断,如果是NULL的就转换成“”;
<%!public String handleNullVal(String str2handle){
if (str2handle==null)
return "";
else
return str2handle;
}
我实现了效果,希望你能看懂