这是我试图实现的java中的分页代码。我有20条记录,其中包含emp_id和emp_name列,我希望使用我的sql工作台显示4页,即每页5条记录但是代码没有执行,表明许多错误都在解决这个问题
<%@ page import ="java.io.*, java.sql.*, java.util.*" %>
<%!
Connection con = null;
ResultSet rs = null;
ResultSet rs1 = null;
int start_row_count, end_row_count, no_of_page, pages;
String page_name="paging.jsp";
%>
<html>
<head>
</head>
<body>
<table border="1" style="width:80%;">
<%
try
{
String pages1=request.getParameter("pages");
if(pages1!=null)
{
pages=Integer.parseInt(pages1);
}
if(pages==0)
pages=1;
if(pages==1)
{
start_row_count=1;
}
else
{
start_row_count=(pages-1)*5;
}
end_row_count=pages*5;
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/shelu", "root", "mysql");
String sql="select * from emp limit" + start_row_count +"5";
Statement st = con.createStatement();
rs = st.executeQuery(sql);
while(rs.next())
{%>
<tr>
<td><%=rs.getInt("emp_id")%></td>
<td><%=rs.getString("emp_name")%></td>
</tr>
<%
}
rs.close();
rs1=st.executeQuery("select count(*) from emp");
int total=0;
if(rs1.next())
total=rs1.getInt(1);
if(total%5==0)
no_of_page=total/5;
else
no_of_page=total/5+1;
%>
<tr>
<%
for(int i=1;i<=no_of_page;i++)
{
out.println("<a href='"+page_name+"?pages="+i+"'>"+i+"</a>");
}
%>
</tr>
<%
} catch(Exception e) {
e.printStackTrace();
}
%>
</table>
</body>
</html>