求jsp代码:要求对mysql数据库查询,实现条件查询。有form,提交按钮!

2025-03-24 06:19:07
推荐回答(2个)
回答1:

不h知道你要实现怎样的查询我给你提供一u个r同样的例子h参考一z下w吧: 8:先接受复选框的参数(假设得到的是一n组id)String ID[]=request。getParameterValues("参数") 4:声明一h个vString SID=""; 判断ID的length: if(ID。length>0) { for(int i=0;i

回答2:

String cardno = request.getParamter("cardno");
String type = request.getParamter("type");

if(cardno == null){
cardno = "";
}
if(type == null){
type = "";
}
String sql = "select * from transaction where 1=1 ";
if(!"".equals(cardno)){
sql += " and cardno like '%"+cardno+"%'";
}
if(!"".equals(type)){
sql += " and type = '"+type+"'";

其中cardno和type是填写的查询条件。
你将sql 传入到java 的查询方法中就ok了