首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

请问jsp加sql语句的有关问题,先谢了

2012-04-23 
请教jsp加sql语句的问题,先谢了String t request.getParameter(t)//从页面接到得值为:CannonString gs

请教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两边不要‘’你试试
[解决办法]
表的字段不要加单引号

热点排行