注册 登录
编程论坛 J2EE论坛

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

墨香555 发布于 2012-04-21 10:37, 585 次点击
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;
    }
1 回复
#2
guoxhvip2012-04-22 01:27
你的gser多了个单引号 如果我没有理解错的话 你的sign是列名 如果是列名 那么你觉得应该加单引号吗
1