新人求助 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