JSP 分页 SQL语句错误 求解!~~~
<%@pagepageEncoding="UTF-8"%><%@pageimport="java.sql.*,bbs.*,java.util.*"%><%finalint...
<%@page pageEncoding="UTF-8"%>
<%@page import="java.sql.*,bbs.*,java.util.*"%>
<%
final int PAGE_SIZE = 5;//每页显示的记录数
int pageNo = 1;//当前是第几页
int totalPages = 0;//总页数
String strPageNo = request.getParameter("pageNo");
if (strPageNo != null && !strPageNo.trim().equals("")) {
try {
pageNo = Integer.parseInt(strPageNo);
} catch (NumberFormatException e) {
pageNo = 1;
}
}
if (pageNo <= 0)
pageNo = 1;
List<Article> articles = new ArrayList<Article>();
Connection conn = DB.getConn();
Statement stmtCount = DB.createStmt(conn);
ResultSet rsCount = DB.executeQuery(stmtCount,"select * from article where pid = 0");
System.out.println("*******");
System.out.println(rsCount);
System.out.println("*******");
rsCount.next();
int totalRecords = rsCount.getInt(1);
totalPages = (totalRecords + PAGE_SIZE - 1) / PAGE_SIZE;
if (pageNo > totalPages)
pageNo = totalPages;
Statement stmt = DB.createStmt(conn);
int startPos = (pageNo - 1) * PAGE_SIZE;
String sql = "select * from article where pid = 0" + startPos + "," + PAGE_SIZE;
ResultSet rs = DB.executeQuery(stmt, sql);//这句有问题
System.out.println("*******");
System.out.println(rs);
System.out.println("*******");
while (rs.next()) {
Article a = new Article();
a.initFromRs(rs);
articles.add(a);
}
DB.close(rsCount);
DB.close(stmtCount);
DB.close(rs);
DB.close(stmt);
DB.close(conn);
%>
---------------------
打印了一下,应该是这句有问题
String sql = "select * from article where pid = 0" + startPos + "," + PAGE_SIZE;
改成
String sql = "select * from article where pid = 0"
能正常显示,但不知道错在哪里。
用的是Oracle数据库 展开
<%@page import="java.sql.*,bbs.*,java.util.*"%>
<%
final int PAGE_SIZE = 5;//每页显示的记录数
int pageNo = 1;//当前是第几页
int totalPages = 0;//总页数
String strPageNo = request.getParameter("pageNo");
if (strPageNo != null && !strPageNo.trim().equals("")) {
try {
pageNo = Integer.parseInt(strPageNo);
} catch (NumberFormatException e) {
pageNo = 1;
}
}
if (pageNo <= 0)
pageNo = 1;
List<Article> articles = new ArrayList<Article>();
Connection conn = DB.getConn();
Statement stmtCount = DB.createStmt(conn);
ResultSet rsCount = DB.executeQuery(stmtCount,"select * from article where pid = 0");
System.out.println("*******");
System.out.println(rsCount);
System.out.println("*******");
rsCount.next();
int totalRecords = rsCount.getInt(1);
totalPages = (totalRecords + PAGE_SIZE - 1) / PAGE_SIZE;
if (pageNo > totalPages)
pageNo = totalPages;
Statement stmt = DB.createStmt(conn);
int startPos = (pageNo - 1) * PAGE_SIZE;
String sql = "select * from article where pid = 0" + startPos + "," + PAGE_SIZE;
ResultSet rs = DB.executeQuery(stmt, sql);//这句有问题
System.out.println("*******");
System.out.println(rs);
System.out.println("*******");
while (rs.next()) {
Article a = new Article();
a.initFromRs(rs);
articles.add(a);
}
DB.close(rsCount);
DB.close(stmtCount);
DB.close(rs);
DB.close(stmt);
DB.close(conn);
%>
---------------------
打印了一下,应该是这句有问题
String sql = "select * from article where pid = 0" + startPos + "," + PAGE_SIZE;
改成
String sql = "select * from article where pid = 0"
能正常显示,但不知道错在哪里。
用的是Oracle数据库 展开
展开全部
赋值语句末尾都没分号肯定不行啊!而且你的分号数量也不对
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
检查检测标点啥的 单引号双引号断点调试一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询