当前位置: 代码迷 >> Java Web开发 >> 请教jsp加sql语句的问题,先谢了
  详细解决方案

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

热度:87   发布时间:2012-04-21 10:37:53.0
请教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;
    }
搜索更多相关主题的帖子: 问题  jsp  sql语句  public  detail  

----------------解决方案--------------------------------------------------------
你的gser多了个单引号 如果我没有理解错的话 你的sign是列名 如果是列名 那么你觉得应该加单引号吗
----------------解决方案--------------------------------------------------------
  相关解决方案