这是我试图实现的java分页代码。我有 20 条记录,其中包含 emp_id 和 emp_name 列,我想使用 4 页显示,即(每页 5 条记录)使用我的 sql 工作台,但代码没有执行,表明有很多错误请解决这个问题
<%@ 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>