请教各位一个分页的问题 谢谢各位大侠啦
代码有些长,其实只看那句sql语句就行 谢谢啦
int pageCount=0;
int pageNow=1;
int pageSize=2;
int rowCount=0;
String s_pageNow=request.getParameter("pageNow");
if(s_pageNow!=null){
pageNow=Integer.parseInt(s_pageNow);
}
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:stuCor");
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
String sql = "select count(*) from cor";
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()){
rowCount =rs.getInt(1);
}
if(rowCount%pageSize==0){
pageCount=rowCount/pageSize;
}else{
pageCount=(rowCount/pageSize)+1;
}
sql = "select top "+pageSize+" * from cor where 学号 not in(select top " +pageSize*(pageNow-1)+" 学号 from cor )";
System.out.print(sql);
rs = stmt.executeQuery(sql);
%>
<h3>所有学生成绩记录如下:</h3>
<table border=2 align="center">
<tr align="center"><td><b>学号</b></td><td><b>姓名</b></td><td><b>英语成绩</b></td><td><b>数学成绩</b></td><td><b>计算机基础</b></td></tr>
<% while (rs.next()) { %>
<tr align=center><td><b><%=rs.getString("学号") %></b></td><td><b><%=rs.getString("姓名") %></b></td><td><b><%=rs.getString("英语成绩") %></b></td><td><b><%=rs.getString("数学成绩") %></b></td><td><b><%=rs.getString("计算机基础") %></b></td></tr>
</table>
<% }%>
<%
rs.close();
stmt.close();
conn.close();
if(pageNow!=1){
out.print("<a href=scan.jsp?pageNow="+(pageNow-1)+">上一页</a>");
}
for(int i=0; i<pageCount;i++){
out.println("<a href=scan.jsp?pageNow="+i+">["+i+"]</a>");
}
if (pageNow!=4){
out.print("<a href=scan.jsp?pageNow="+(pageNow+1)+">下一页</a>");
}
%>
现在的问题是,总是说rs = stmt.executeQuery(sql);这一行错了。并且报错是说sql有语法错误,当pageNow为1的时候,sql语句为:select top 2 * from cor where 学号 not in(select top 0 学号 from cor) ;是不是 不能为0呀,也就是说 当p