请教jsp加sql语句的问题,先谢了
String t= request.getParameter("t");//从页面接到得值为:Cannon
String gser =request.getParameter("gser");//从页面接到得值为:sign
readcount=c.getGoodsCount("select count(*) from goods,detail where goods.id=detail.tid and '"+gser+"' like '%"+t+"%'");//就是这条语句的问题,我把'"+gser+"'换成sign就能得到readcount 的值。谁能告诉我为什么啊????????、
System.out.println(readcount);//但为什么得到的值是0啊。
getGoodsCount()方法如下:
public int getGoodsCount(String sql){
Connection conn=getConn();
ResultSet rs=null;
int i=0;
try {
PreparedStatement pst = conn.prepareStatement(sql);
rs=pst.executeQuery();
rs.next();
i= rs.getInt(1);
} catch (
SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return i;
}
------解决方案--------------------
readcount=c.getGoodsCount("select count(*) from goods,detail where goods.id=detail.tid and "+gser+" like '%"+t+"%'");
这样写试试
------解决方案--------------------select count(*) from goods,detail where goods.id=detail.tid and "+gser+" like '%"+t+"%'
gser两边不要‘’你试试
------解决方案--------------------表的字段不要加单引号