问题描述
publicList<Houst>getHoust(Stringtitle,intpriceid){List<Houst>list=newArrayList<Houst>();try{Stringsql="selecta.*,b.name,c.telephone,d.nameasname2,e.nameasname3fromhousea,typesb,usersc,streetd,districtewherea.type_id=b.idanda.user_id=c.idanda.street_id=d.idandd.district_id=e.idanda.titlelike?";if(priceid==1){sql+=sql+"anda.price<100";}if(priceid==2){sql+=sql+"anda.price>100anda.price<200";}if(priceid==3){sql+=sql+"anda.price>200";}conn=getConn();ps=conn.prepareStatement(sql);ps.setString(1,null==title?"%":"%"+title+"%");rs=ps.executeQuery();while(rs.next()){Housth=newHoust();h.setContact(rs.getInt("contact"));h.setDescription(rs.getString("description"));h.setFloorage(rs.getInt("floorage"));h.setId(rs.getInt("id"));h.setPrice(rs.getInt("price"));h.setPubdate(rs.getDate("pubdate"));h.setStreet_id(rs.getInt("street_id"));h.setTitle(rs.getString("title"));h.setType_id(rs.getInt("type_id"));h.setUser_id(rs.getInt("user_id"));h.setTypename(rs.getString("name"));h.setUserphone(rs.getString("telephone"));h.setDistrict(rs.getString("name2"));h.setStreet(rs.getString("name3"));list.add(h);}}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}catch(Exceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}finally{closeAll();}returnlist;}为什么只有一个参数,他报错Novaluespecifiedforparameter2前面的不进if里又可以..但是数据库里可以在后面加上if里的语句不会报错求大神帮帮忙
解决方案
解决方案二:
sql+=sql+"anda.price<100";改成sql+="anda.price<100";