String where = "where 1=1";
if(!zyName.equals("")){
where = where + " and zyName ='"+zyName+"' ";
}
if(!source.equals("")){
where = where + " and source like '%"+source+"%'";
}
Page pagecx=db.selectAllRowsPage("select zyId,zyName,otherName,source,zucheng,useMethod,zhuzhi,bz from zy_info"+ where);
想在sql中加入where 但是怎么弄呢???
if(!zyName.equals("")){
where = where + " and zyName ='"+zyName+"' ";
}
if(!source.equals("")){
where = where + " and source like '%"+source+"%'";
}
Page pagecx=db.selectAllRowsPage("select zyId,zyName,otherName,source,zucheng,useMethod,zhuzhi,bz from zy_info"+ where);
想在sql中加入where 但是怎么弄呢???
解决方案 »
- richfaces之listshuttle如何在后台获得两个list中的值?
- 为什么一直说打开不了applicationContext.xml文件啊
- java调用dll的问题
- 请求下面这个关于struts验证产生的错误的帮助
- 请问怎样在spring+hibernate+struts中统计在线人数,谢谢!!!
- 本地的servlet可以访问其他机器上的servlet吗?
- 关于hibernate.cfg.xml怎么样也找不到?太奇怪了..
- 我正在学做jsp网页,请问大侠当今国内公司里做jsp网页是用struts多还是JBuild和Dreamweaver多啊?也就是这三者哪个用得最普遍啊?谢谢!
- struts取值问题。
- 初学XML,希望各位高手、仁兄帮助!
- struts中double,int,string的判断
- 请教高手,JSP关于自定义标签
你这个sql语句不是加了where吗???
"select zyId,zyName,otherName,source,zucheng,useMethod,zhuzhi,bz from zy_info where 你的条件判定比如 zyId=1"
/*
String where = "where 1=1";
if(!zyName.equals("")){
where = where + " and zyName ='"+zyName+"' ";
}
if(!source.equals("")){
where = where + " and source like '%"+source+"%'";
}
Page pagecx=db.selectAllRowsPage("select zyId,zyName,otherName,source,zucheng,useMethod,zhuzhi,bz from zy_info"+ where);
想在sql中加入where 但是怎么弄呢???
*/select zyId,zyName,otherName,source,zucheng,useMethod,zhuzhi,bz
from zy_info
where 1 = 1 and source like '%???%' --???表示你那个参数值!
--按楼主的想法可以用动态SQL实现create proc get_where(@where varchar(1000))
as
being
declare @sql varchar(8000)
set @sql = 'select zyId,zyName,otherName,source,zucheng,useMethod,zhuzhi,bz from zy_info'
set @where = ' where 1 = 1'
if(/*楼主要判断的条件*/)
set @where = @where + 'source like ''%...%'''
set @sql = @sql + @where
exec(@sql)
end
goexec get_where 'aaa'
begin
今天老打错字,别介意!
begin
今天老打错字,别介意!
--也可以这样declare @source varchar(100)
set @source = 'aaa'select zyId,zyName,otherName,source,zucheng,useMethod,zhuzhi,bz
from zy_info
where 1 = 1 and source like '%' + @source + '%'
if(!fanghao.equals("")){
where = where + " and fanghao ='"+fanghao+"' ";
}
if(!xm.equals("")){
where = where + " and xm like '%"+xm+"%'";
}
if(!djrq.equals("")){
where = where + " and substring(djrq,1,10) ='"+djrq+"'";
}
Page pageDjda = db.selectAllRowsPage("select id,xm,fanghao,sex,zjType,zjNumber,jtzz,djrq,ysje,ssje,djje,daynumber from dengjida "+where+" and zt='1'");这句话可以执行 我想写一个类似于这个的 怎么弄呢 你的那个可以实现
一样的,按这个多定义两个变量把两外两个参数对应写进去就可以,关键是你只给了程序获取参数值的,在SQL里怎么知道那几个参数。