BBS分页问题
一、BBS分页问题:
1)想实现分页功能
2)以下是有问题的平板式BBS分页程序( ShowArticleFlat.jsp)。
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ page import = "java.sql.*"%>
<%
int pageSize = 3;
String strPageNo = request.getParameter("pageNo");
int pageNo;
if(strPageNo == null || strPageNo.equals("")){
pageNo = 1;
}else{
pageNo = Integer.parseInt(strPageNo.trim());
}
int startPos = (pageNo - 1) * pageSize;
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from article where pid = 0 order by pdate desc limit" + startPos + "," + pageSize);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body>
<a href="Post.jsp">发表新帖</a>
<table border = "1">
<%
while(rs.next()){
%>
<tr>
<td>
<%=rs.getString("title")%>
</td>
</tr>
<%
}
rs.close();
stmt.close();
conn.close();
%>
</table>
</body>
</html>
3)以下是运行后报的错误。
HTTP Status 500 -
________________________________________
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Exception in JSP: /ShowArticleFlat.jsp:24
21: String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
22: Connection conn = DriverManager.getConnection(url);
23: Statement stmt = conn.createStatement();
24: ResultSet rs = stmt.executeQuery("select * from article where pid = 0 order by pdate desc limit" + startPos + "," + pageSize);
25:
26:
27: %>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
javax.servlet.ServletException: 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 'limit0,3' at line 1
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.ShowArticleFlat_jsp._jspService(ShowArticleFlat_jsp.java:114)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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 'limit0,3' at line 1
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1026)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2477)
com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1422)
org.apache.jsp.ShowArticleFlat_jsp._jspService(ShowArticleFlat_jsp.java:66)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.
________________________________________
Apache Tomcat/5.5.27
4)显示的是sql语句有错,可是把sql语句放在dos窗口中运行时,并没有显示错误,可以从数据库中取出相应的内容。
找不出哪里的问题,帮帮忙呗,谢谢了