标题:新人求助 web分页mysql中sql语句出错
取消只看楼主
a1026438864
Rank: 1
来 自:武汉
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-11-1
结帖率:0
已结贴  问题点数:20 回复次数:0 
新人求助 web分页mysql中sql语句出错
//====================分页=============
            int pagesize = 3;//每页显示多少条记录
            int pagenow = 1;//希望显示第几页
            int rowcount = 0;//一共有多少条记录  查表的来
            int pagecount = 0;//一共有几页  计算的来
        
            //得到rowcount
            Class.forName("com.mysql.jdbc.Driver");
            cn = DriverManager.getConnection("jdbc:mysql://localhost/userlist", "root", "123");
            ps = cn.prepareStatement("select count(*) from userlist");
            rs = ps.executeQuery();
            
            if(rs.next()){
               
                rowcount = rs.getInt(1);
            }
            //计算pagecount
            if(rowcount%pagesize==0){
                pagecount = rowcount/pagesize;
            }else{
                pagecount = rowcount/pagesize+1;
            }
            String sql = "select * from userlist limit ("+pagenow+"-1)*"+pagesize+","+pagesize+"";
            //String sql = "select * from userlist limit 0,3";
            ps = cn.prepareStatement(sql);
            //ps.setInt(1, pagenow);
            //ps.setInt(2, pagesize);
            //ps.setInt(3, pagesize);
            
            rs = ps.executeQuery();
            
            pw.println("<table border=1>");
            pw.println("<tr><th>ID</th><th>NAME</th><th>PASSWD</th><th>EMAIL</th><th>GRADE</th></tr>");   
            while(rs.next()){
               
                pw.println("<tr>");
                pw.println("<td>"+rs.getInt(1)+"</td>");
                pw.println("<td>"+rs.getString(2)+"</td>");
                pw.println("<td>"+rs.getString(3)+"</td>");
                pw.println("<td>"+rs.getString(4)+"</td>");
                pw.println("<td>"+rs.getInt(5)+"</td>");
                pw.println("</tr>");
               
            }
            pw.println("</table>");


错误You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(1-1)*3,3' at line 1
搜索更多相关主题的帖子: localhost sql语句 mysql count 记录 
2013-11-01 20:59



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-422907-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.478458 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved